#include<iostream>
#include<stdio.h>
#include<cstring>

using namespace std;

int main()
{
    int limit;
    scanf("%d", &limit);
    cin.ignore();
    while (limit >0)
    {
        string input;
        getline(cin, input);
        string temp[200];
        int jml = 0;
        int maxl = 0;
        int templ = 0;
        string asd = "";
        for(int i = 0; i<input.length(); i++)
        {
            if((input[i]>='a' && input[i]<='z') || (input[i]>='A' && input[i]<='Z') || (input[i]>='0' && input[i]<='9'))
            {
                asd+=input[i];
                templ++;
            }
            else
            {
                if(asd!="")
                {
                    temp[jml] = asd;
                    asd = "";
                    jml++;
                    if (templ>maxl)
                    {
                        maxl = templ;
                    }
                    templ=0;
                }
            }
            if(i==input.length()-1 && asd!="")
            {
                temp[jml] = asd;
                asd = "";
                jml++;
                if (templ>maxl)
                {
                    maxl = templ;
                }
                templ=0;
            }
        }
        string temphasil[100];
        int oddeven = 0;
        for (int i=0;i<jml;i++)
        {
            for (int j=0;j<temp[i].length();j++)
            {
                if (oddeven%2==0)
                {
                    temphasil[j]+=temp[i][j];
                }
                else
                {
                    temphasil[j]+=temp[i][temp[i].length()-j-1];
                }
            }
            oddeven++;
        }
        string hasil = "";
        for (int i=0; i<maxl; i++)
        {
            hasil+= temphasil[i];
            if(i<maxl-1)
            {
                hasil+=" ";
            }
        }
        cout<<hasil<<endl;
        limit--;
    }
    return 0;
}
#include <iostream>
using namespace std;

int main() {
	// your code goes here
	return 0;
}