#include<bits/stdc++.h>
using namespace std;
const long long M=2e5+10,MOD=1000000007;
typedef long long ll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
cin>>t;
while(t--){
string s;
cin>>s;
deque<char>dp;
for(char c:s)dp.push_back(c);
int q;
cin>>q;
int cnt=0;
while(q--){
int type;
cin>>type;
type--;
if(!type)cnt++;
else{
int p;
char ch;
cin>>p>>ch;
if(p==1){
if(cnt&1)dp.push_back(ch);
else dp.push_front(ch);
}
else{
if(cnt&1)dp.push_front(ch);
else dp.push_back(ch);
}
}
}
string p="";
cnt%=2;
while(!dp.empty())p+=(dp.back()),dp.pop_back();
if(!cnt)reverse(p.begin(),p.end());
cout<<p<<"\n";
}
return 0;
}