#C3353. Key String Rotation

    ID: 46771 Type: Default 1000ms 256MiB

Key String Rotation

Key String Rotation

You are given a string S and an integer K. Your task is to generate the first K key strings by performing a left cyclic rotation on S. In each rotation, the first character of the string is moved to the end. Formally, if \(S = s_1s_2\ldots s_n\), then after one rotation it becomes \(s_2s_3\ldots s_ns_1\).

For example, if \(S = \texttt{abcdef}\) and \(K = 3\), the generated key strings will be:

  • \(\texttt{bcdefa}\)
  • \(\texttt{cdefab}\)
  • \(\texttt{defabc}\)

Process each test case independently.

inputFormat

The input begins with an integer T representing the number of test cases. Each test case consists of two lines:

  1. A line containing the string S.
  2. A line containing the integer K.

It is guaranteed that S is non-empty and K is a positive integer.

outputFormat

For each test case, output a single line containing the first K key strings separated by a space. Each key string is generated by performing one left cyclic rotation on the string from its previous state.

## sample
1
abcdef
3
bcdefa cdefab defabc

</p>