#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
int t;
cin >> t;
while (t--){
int q, ok = 0;
string s, s1, s2;
cin >> s >> q;
for (int i = 0; i < q; i++){
int a, d;
char c;
cin >> a;
if (a == 1){
ok ^= 1;
} else {
cin >> d >> c;
if (d == 1){
if (ok) s2 += c;
else s1 += c;
} else {
if (ok) s1 += c;
else s2 += c;
}
}
}
if (ok){
reverse(s.begin(), s.end());
reverse(s2.begin(), s2.end());
s = s2 + s + s1;
} else {
reverse(s1.begin(), s1.end());
s = s1 + s + s2;
}
cout << s << endl;
}
}