/*
Mail to : miyubai@gamil.com
My Blog : www.baiyun.me
Link : http://www.cnblogs.com/MiYu || http://www.cppblog.com/MiYu
Author By : MiYu
Test : 1
Complier : g++ mingw32-3.4.2
Program : HDU_2573
Doc Name : Typing
*/
//#pragma warning( disable:4789 )
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <utility>
#include <queue>
#include <stack>
#include <list>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;
bool isup = false;
int main ()
{
int T;
cin >> T;
while ( T -- ) {
int N;
string str, word;
cin >> N;
while ( N -- ) {
cin >> str;
if ( str.size() == 1 ) {
word += char( isup ? toupper(str[0]) : tolower (str[0]) );
} else if ( str == "Caps" ) isup = !isup;
else {
cin >> str;
word += char( !isup ? toupper(str[0]) : tolower (str[0]) );
}
}
cout << word << endl;
isup = false;
}
return 0;
}