#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define print(v) for(auto &u:v) cout << u << " "
#define printp(v) for(auto e:v) cout<<e.first<<" "<<e.second<<endl;
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pb push_back
#define printl(li) for(auto &u:li) cout << u;
void solve()
{
string str; cin >> str;
list <char> li;
for(int i=0; i<str.size(); i++) li.pb(str[i]);
int q; cin >> q;
bool flag = true;
while(q--){
int check; cin >> check;
if(check==2)
{
int d; cin >> d;
char ch; cin >> ch;
d==1 ? li.push_front(ch) : li.push_back(ch);
}
else if(check == 1){
li.reverse();
}
}
printl(li);
cout << endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1; cin >> t;
while(t--)
{
solve();
}
return 0;
}