#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using ll = long long;
int main() {
FAST;
int tc = 1, ti;
cin >> tc;
for (ti = 1; ti <= tc; ++ti) {
string s;
cin >> s;
deque<char> d(s.begin(), s.end());
int q, t, m, f;
char c;
f = 1;
cin >> q; while (q--) {
cin >> t;
if (t == 1) {
f ^= 1;
} else {
cin >> m >> c;
if (f == 1) {
if (m == 1) d.push_front(c);
else d.push_back(c);
} else {
if (m == 2) d.push_front(c);
else d.push_back(c);
}
}
}
if (f == 0) reverse(d.begin(), d.end());
for (char x : d) cout << x;
cout << "\n";
}
return 0;
}