#include <iostream>
#include <string>
using namespace std;
int main() {
int N;
cin >> N;
string word;
for (int i = 0; i < N; i++) {
cin >> word;
if (word.length() > 0) {
if (word[0] >= 'a' && word[0] <= 'z')
word[0] = word[0] - ('a' - 'A');
if (word[word.length() - 1] >= 'A' && word[word.length() - 1] <= 'Z')
word[word.length() - 1] = word[word.length() - 1] + ('a' - 'A');
}
cout << word << " ";
}
cout << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgICBpbnQgTjsKICAgIGNpbiA+PiBOOwoKICAgIHN0cmluZyB3b3JkOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBOOyBpKyspIHsKICAgICAgICBjaW4gPj4gd29yZDsKCiAgICAgICAgaWYgKHdvcmQubGVuZ3RoKCkgPiAwKSB7CiAgICAgICAgICAgIGlmICh3b3JkWzBdID49ICdhJyAmJiB3b3JkWzBdIDw9ICd6JykgCiAgICAgICAgICAgICAgICB3b3JkWzBdID0gd29yZFswXSAtICgnYScgLSAnQScpOwoKICAgICAgICAgICAgaWYgKHdvcmRbd29yZC5sZW5ndGgoKSAtIDFdID49ICdBJyAmJiB3b3JkW3dvcmQubGVuZ3RoKCkgLSAxXSA8PSAnWicpIAogICAgICAgICAgICAgICAgd29yZFt3b3JkLmxlbmd0aCgpIC0gMV0gPSB3b3JkW3dvcmQubGVuZ3RoKCkgLSAxXSArICgnYScgLSAnQScpOwogICAgICAgIH0KCiAgICAgICAgY291dCA8PCB3b3JkIDw8ICIgIjsKICAgIH0KCiAgICBjb3V0IDw8IGVuZGw7CgogICAgcmV0dXJuIDA7Cn0K