#include <iostream>
#include <cmath>
#include <string>
using namespace std;
#define MAXLENGTH 10000
int main() {
    int N{ 0 }, n{ 0 };
    string cypherText, plainText;
    char* cstr = new char[MAXLENGTH];
    cin >> N;
    cin.get();
    while (N--) {
        cin.getline(cstr, MAXLENGTH);
        n = sqrt(strlen(cstr));
        //starting with the n-1 index, keep adding n until n*(n-1)+n-1 = n^2-1
        for (int i = n - 1; i >= 0; i--) {
            for (int j = 0; j < n; j++) {
                cout << *(cstr+n*j + i);
            }
        } cout << endl;
    }
    delete [] cstr;
}