#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
char a[1000005],b[1000005];
scanf("%d",&n);
getchar();//读取回车
while(n--)
{
memset(a,'\0',sizeof(a));
memset(b,'\0',sizeof(b));//注意每次清空
gets(a);//读取回车
int j = 0;
for(int i = 0;i<strlen(a);i++ ){
if(a[i]==' ')
{
if(a[i+1]>='a'&&a[i+1]<='z')
b[j] = a[i+1]-32;
else if(a[i+1]>='A'&&a[i+1]<='Z')
b[j] = a[i+1];
i++;
}else if(a[i]>='A'&&a[i]<='Z')
{
b[j] = a[i] + 32;
}else b[j] = a[i];
j++;
}
printf("%s\n",b);
}
return 0;
}