#include "stdafx.h"
#include<iostream>
using namespace std;
//#include<stdio.h>
//#include<math.h>
//#include<vector>
int main( )
{
int num,i,j,tmp,begin,end,length;
cin>>num;
getchar();
for(i=0;i<num;i++)
{
char s[1000];
cin.getline(s, 1000);
length=strlen(s);
if (length>1000) return 1;
begin=0;
for(j=0;j<length;j++)
{
if(s[j]!=' ' && s[j]!='\0')
continue;
else
{
end=j-1;
for(tmp=end;tmp>=begin;tmp--)
cout<<s[tmp];
cout<<' ';
begin=j+1;
}
}
for(tmp=length-1;tmp>=begin;tmp--)
cout<<s[tmp];
//cout<<' ';
cout<<endl;
}
system("Pause");
return 0;
}
#include<iostream>
using namespace std;
//#include<stdio.h>
//#include<math.h>
//#include<vector>
int main( )
{
int num,i,j,tmp,begin,end,length;
cin>>num;
getchar();
for(i=0;i<num;i++)
{
char s[1000];
cin.getline(s, 1000);
length=strlen(s);
if (length>1000) return 1;
begin=0;
for(j=0;j<length;j++)
{
if(s[j]!=' ' && s[j]!='\0')
continue;
else
{
end=j-1;
for(tmp=end;tmp>=begin;tmp--)
cout<<s[tmp];
cout<<' ';
begin=j+1;
}
}
for(tmp=length-1;tmp>=begin;tmp--)
cout<<s[tmp];
//cout<<' ';
cout<<endl;
}
system("Pause");
return 0;
}