#include <bits/stdc++.h>
#define int long long
using namespace std;
namespace solve {
namespace test_case {
void main() {
string s; int q, x; cin >> s >> q;
deque<char> dq(s.begin(), s.end());
bool f (false);
while (q-- && cin >> x) {
if (x == 1) {
f = !f;
} else {
int d; char c; cin >> d >> c;
(d == 1 && !f) || (d == 2 && f) ? dq.push_front(c) : dq.push_back(c);
}
}
if (f) reverse(dq.begin(), dq.end());
for (char c : dq) cout << c;
cout << '\n';
}
}
void main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
test_case::main();
}
}
}
signed main() { solve::main(); }