#include <iostream>#include <algorithm>
#include <string>
//#include <cstdio>
using namespace std;
int main()
{
int t,loc;
// freopen("in.in", "r", stdin);
cin >> t;
cin.get();//刚开始把回车读掉
string str;
while (t--)
{
getline(cin, str);
loc = 0;
while (str.find(" ", loc) != string::npos)//反转前n-1个单词
{
reverse( str.begin() + loc, str.begin() + str.find(" ", loc));
loc=str.find(" ", loc) + 1;
}
reverse(str.begin() + loc, str.end());
cout << str << endl;
}
// fclose(stdin);
return 0;
}