#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
string s; cin >> s;
deque<char> d (s.begin(), s.end());
int r = 0;
int n; cin >> n;
for (int i = 0; i < n; ++i) {
int q; cin >> q;
if (q == 1) r ^= 1;
else {
int x; cin >> x; x %= 2;
char c; cin >> c;
if (x ^ r) d.push_front(c);
else d.push_back(c);
}
}
if (r) reverse(d.begin(), d.end());
for (int i = 0; i < d.size(); ++i) {
cout << d[i];
}
cout << '\n';
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(nullptr);
i64 T; cin >> T;
while(T--) solve();
return 0;
}