11716

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>

using namespace std;

int main()
{
	int t,l,m;
	string str;
	cin>>t;
	getchar();

	while(t--)
	{
		char gr[105][105];
		getline(cin,str);
		l=str.size();
		m=sqrt(l);
		if(m*m!=l)
		{
			cout<<"INVALID\n";
		}
		else
		{
			int k=0;
			for(int i=0;i<m;i++)
			{
				for(int j=0;j<m;j++)
				{
					gr[i][j]=str[k];
					k+=1;
				}
			}

			for(int i=0;i<m;i++)
			{
				for(int j=0;j<m;j++)
					cout<<gr[j][i];
			}
			cout<<"\n";
		}
	}
	return 0;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *