#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(n) n.begin(),n.end()
#define sz(n) (ll) n.size()
#define endl '\n'
const double PI = 3.14159265358979323846;
const ll mod = 1e9 + 7;
void test_case() {
string s;
cin >> s;
int q;
cin >> q;
deque<char> front, back;
for (char c : s) {
back.push_back(c);
}
bool check = false;
while (q--) {
int x;
cin >> x;
if (x == 1) {
check = !check;
} else if (x == 2) {
int d;
char c;
cin >> d >> c;
if (check) {
if (d == 1) {
back.push_back(c);
} else {
front.push_front(c);
}
} else {
if (d == 1) {
front.push_front(c);
} else {
back.push_back(c);
}
}
}
}
if (check) {
for (auto it = back.rbegin(); it != back.rend(); ++it) {
cout << *it;
}
for (auto it = front.rbegin(); it != front.rend(); ++it) {
cout << *it;
}
} else {
for (char c : front) {
cout << c;
}
for (char c : back) {
cout << c;
}
}
cout << endl;
}
int32_t main() {
//freopen("input.txt","r", stdin);
//freopen("output.txt","w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t = 1;
cin >> t;
while(t--) {
test_case();
}
}