//
//#include<bits/stdc++.h>
#include<iostream>
#include<stack>
using namespace std;
stack<char> st;
int main()
{
int n; char ch;
while( cin>>n )
{
cin.get();
while( n-- )
{
while( cin.get(ch) && ch!='\n' )
{
if( ch==' ' )
{
while( st.size() )
{ cout<<st.top(); st.pop(); }
cout<<' ';
}
else
st.push(ch);
}
while( st.size() )
{ cout<<st.top(); st.pop(); }
cout<<endl;
}
}
return 0;
}