#include <bits/stdc++.h>
//#define ll long long int
using namespace std;
typedef long long int ll;
priority_queue<int, vector<int>, greater<int>> pq;
const ll md = 1e9 + 7;
const ll md1 = 998244353;
map<ll, vector<ll>> tree;
//map<ll, int> mp;
ll get(ll l,ll r,ll n){
}
void sufi() {
string s;
cin>>s;
vector<char>v1;
vector<char>v2;
int c=0;
int q;
cin>>q;
while(q--){
int a;
cin>>a;
if(a==1)c=abs(c-1);
else{
int d;
cin>>d;
char ch;
cin>>ch;
if(d==1){
if(c==0)v1.push_back(ch);
else v2.push_back(ch);
}
else{
if(c==0)v2.push_back(ch);
else v1.push_back(ch);
}
}
}
//cout<<v1.size()<<" "<<v2.size()<<endl;
if(c==0){
if(v1.size()){
auto it=v1.end();
it--;
while(1){
cout<<*it;
if(it==v1.begin())break;
it--;
}
}
cout<<s;
if(v2.size()){
for(auto it:v2)cout<<it;
}
cout<<endl;
}
else{
if(v2.size()){
auto it=v2.end();
it--;
while(1){
cout<<*it;
if(it==v2.begin())break;
it--;
}
}
auto it1=s.end();
it1--;
while(1){
cout<<*it1;
if(it1==s.begin())break;
it1--;
}
if(v1.size()){
for(auto it:v1)cout<<it;
}
cout<<endl;
}
}
int main() {
int t;
cin>>t;
while (t--) {
sufi();
tree.clear();
//mp.clear();
}
return 0;
}