#include<iostream>
#include<string>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
string s;
cin >> s;
int a = s.size();
bool t = false;
for (int j = 0; j < a; j++)
{
if (((s[j] >= 65 && s[j] <= 90) || (s[j] >= 97 && s[j] <= 122)) && t == false)
{
if (s[j] >= 97 && s[j] <= 122)
s[j] -= 32;
t = true;
cout << s[j];
continue;
}
if (t == true && (s[j] >= 65 && s[j] <= 90))
s[j] += 32;
cout << s[j];
}
cout << endl;
}
}