/*对于这道题我表示非常无语。对getchar的用法不熟。
主要是读入字符的问题。然后将每个词入栈。再按顺序弹栈即可。
学会用getchar处理单个字符和对行数的控制。*/
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int n,top;
char a[1100];
char c;
while(scanf("%d",&n)==1&&n)
{
getchar();
for(int i=0; i<n; i++)
{
top=0;
while((c=getchar())!='\n')
{
if(c!=' ')
{
a[top++]=c;
}
else
{
while(top>=1)
{
top--;
printf("%c",a[top]);
}
printf(" ");
}
}
while(top>=1)
{
top--;
printf("%c",a[top]);
}
printf("\n");
}
}
return 0;
}