// PIPRA || HABIB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define pb push_back
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define endl "\n"
void pipra(){
string s;
cin >> s;
deque<char> dq;
for(auto ch: s) {
dq.push_back(ch);
}
int q; cin >> q;
int count = 0;
while(q--){
int type;
cin >> type;
count += (type == 1);
if(type == 2){
int d;
char ch;
cin >> d >> ch;
d--;
if(count & 1) d ^= 1;
if(d == 0){
dq.push_front(ch);
}
else{
dq.push_back(ch);
}
}
}
string res = "";
for(auto e: dq) res += e;
if(count & 1){
reverse(all(res));
}
cout << res << endl;
}
int32_t main(){
// HABIB
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t; cin>>t;
while(t--) {
pipra();
}
return 0 ;
}