#include<iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
char a[100];
char res[100];
char *Reverse(char *s)
{
// p指向字符串头部
char *p = s ;
// q指向字符串尾部
char *q = s ;
while(*q)
++q ;
q -- ;
// 交换并移动指针,直到p和q交叉
while(q > p)
{
char t = *p ;
*p++ = *q ;
*q-- = t ;
}
return s ;
}
int main(){
int t;
cin>>t;
gets(a);
while(t--){
int i , j;
gets(a);
int leng = strlen(a);
int pa=0;
for(i=0;i<=leng;i++)
if(a[i]==' '||a[i]=='\0'){
int k=0;
for(j=pa;j<i;j++){
res[k] = a[j];
k++;
}res[k] = '\0';
Reverse(res);
if(a[i]==' ')
cout<<res<<" ";
else
cout<<res;
pa = i+1;
}
cout<<endl;
}
return 0;
}