#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
{
int N;
cin>>N;
getchar();
while(N--)
{
int m=0;
string str;
getline(cin,str);
for(int i=0;i<str.length();i++)
{
if(str[i]==' ')
{
for(int j=i-1;j>=m;j--)
{
cout<<str[j];
}
cout<<" ";
m=i+1;
}
}
for(int j=str.length()-1;j>=m;j--)
{
cout<<str[j];
}
cout<<endl;
}
return 0;
}