#include <iostream>
using namespace std;
struct field{
string f;
string s;
int num;
};
void prints(field arr[], int n, string p[], string q[], string l[], string m[], string b[]){
int ind =0;
for(int i =0;i<n;i++){
if(arr[i].num == 1){
p[i] = arr[i%n].f;
b[ind++] = p[i];
q[i] = arr[i%n].s;
b[ind++] = q[i];
}
else if(arr[i].num ==0){
l[i] = arr[i%n].f;
b[ind++] = l[i];
m[i] = arr[i%n].s;
b[ind++] = m[i];
}
else{
p[i] = arr[i%n].f;
b[ind++] = p[i];
q[i] = arr[i%n].f;
b[ind++] = q[i];
l[i] = arr[i%n].f;
b[ind++] = l[i];
m[i] = arr[i%n].f;
b[ind++] = m[i];
}
}
/* for(int i =0;i<4*n;i++){
cout<<b[i];
}*/
}
void lower(char C, char &s){
int asc = C;
if(C>='A' && C<='Z'){
asc = asc+32;
s = asc;
cout<<s;
}
else if(C>='a' && C<='z'){
s =C;
cout<<s;
}
}
void lowerIntoUpp(char c, char &s){
if(c>='a'&&c<='z'){
s= c-32;
cout<<s;
}
else if(c>='A'&&c<='Z'){
s = c;
cout<<s;
}
}
void convert(string str, string &a){
lowerIntoUpp(str[0], a[0]);
for(int i = 1;i<str.length();i++){
lower(str[i], a[i]);
cout<<a[i];
}
}
void p(field arr[], int n){
string p[n], q[n], l[n], m[n], b[4*n], r[4*n], t[4*n];
prints(arr, n, p, q, l, m, b);
for(int i = 0;i<4*n;i++){
convert(b[i], t[i]);
}
}
int main(){
int n;
cin>>n;
field arr[n];
for(int i =0;i<n;i++){
cin>>arr[i].f>>arr[i].s>>arr[i].num;
}
p(arr, n);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpzdHJ1Y3QgZmllbGR7CglzdHJpbmcgZjsKCXN0cmluZyBzOwoJaW50IG51bTsKfTsKdm9pZCBwcmludHMoZmllbGQgYXJyW10sIGludCBuLCBzdHJpbmcgcFtdLCBzdHJpbmcgcVtdLCBzdHJpbmcgbFtdLCBzdHJpbm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