/**
* written by Binoy Barman .
**/
#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define all(v) v.begin(), v.end()
#define Too_Many_Jobs int tts, tc = 1; cin >> tts; hell: while(tts--)
#define Dark_Lord_Binoy ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifdef LOCAL
#include "unravel.hpp"
#else
#define dbg(...) 42
#endif
#define int long long
int32_t main() {
Dark_Lord_Binoy
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
Too_Many_Jobs {
string s;
cin >> s;
deque<char> pre, suf;
int q;
cin >> q;
bool rev = false;
while(q--) {
int t;
cin >> t;
if(t == 1) {
rev = rev ^ 1;
}
else {
int d;
char c;
cin >> d >> c;
if(!rev) {
if(d == 1) pre.push_front(c);
else suf.push_back(c);
}
else {
if(d == 2) pre.push_front(c);
else suf.push_back(c);
}
}
}
if(rev) {
reverse(all(s));
for(auto c : suf) cout << c;
cout << s;
for(auto c : pre) cout << c;
}
else {
for(auto c : pre) cout << c;
cout << s;
for(auto c : suf) cout << c;
}
cout << nl;
}
return 0;
}