#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
void judge()
{
#ifndef ONLINE_JUDGE
freopen("error.txt", "w", stderr);
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
const ll N=2e5 +5;
void soln(){
string s;
cin>>s;
int q;
cin>>q;
while(q--){
int t;
cin>>t;
if(t==1){
reverse(s.begin(),s.end());
}
else{
int a;
char c;
cin>>a>>c;
if(a==1){
s= c+s;
}
else{
s= s+c;
}
}
}
cout<<s<<endl;
}
int main() {
// judge();
int t;
cin >> t;
while (t--) soln();
}