Secret Letter

No attempts yetTime limit1sMemory limit128 MB

Problem

Seonyeong wrote a love letter to her boyfriend. To keep others from reading it, she encrypts the letter as follows.

  1. Write the letter's characters into a square grid, one character at a time, in row-major order (left to right, top to bottom), starting at the top-left cell.
  2. Rotate this square 90 degrees clockwise.
  3. Read the rotated square again in row-major order, from the first row to the last row, and concatenate everything into a single line. The resulting string is the ciphertext.

Seonyeong never uses spaces, so the length of the letter is always a perfect square.

For example, if the original letter is RosesAreRedVioletsAreBlue (length 25, i.e. a 5×5 square), the encrypted letter becomes eedARBtVrolsiesuAoReerles.

Given an encrypted letter, write a program that restores the original letter.

Input

The first line contains the number of test cases $T$. $T$ is at most $100$.

Each of the next $T$ lines contains one encrypted letter. Each letter consists only of uppercase and lowercase English letters, and its length is at least $1$, at most $10000$, and always a perfect square.

Output

For each test case, print the restored original letter on its own line.