#include <bits/stdc++.h>
using namespace std;
// Macros
#define REP(i, j, n) for(int i = j; i < n; i++)
#define trav(i, a) for(auto i: a)
#define all(x) x.begin(), x.end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define F first
#define S second
#define GCD __gcd
// Type Names
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;
// Global Variables
const int MOD = 1e9 + 7;
// custom hash
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
// print vector X)
template <typename T>
void print_vector(vector<T> a){
int n = a.size();
for (int i = 0; i < n; i++){
cout << a[i] << (i == n - 1 ? "\n" : " ");
}
}
template <typename T>
void print_2d_vector(vector<vector<T>> a){
int row = a.size();
int col = a[0].size();
for (int i = 0; i < row; i++){
for (int j = 0; j < col; j++){
cout << a[i][j] << " ";
}
cout << "\n";
}
}
template <typename T>
void print_stack(stack<T> st){
while (!st.empty()){
cout << st.top() << " ";
st.pop();
}
cout << "\n";
}
template <typename T>
void print_set(set<T> s){
for (auto itr = s.begin(); itr != s.end(); itr++){
cout << *itr << " ";
}
cout << "\n";
}
template <typename T>
void print_set(multiset<T> s){
for (auto itr = s.begin(); itr != s.end(); itr++){
cout << *itr << " ";
}
cout << "\n";
}
string int_to_bin(ll n){
string ans = "";
while (n) {
ans = to_string(n % 2) + ans;
n /= 2;
}
return ans;
}
ull bin_to_int(string s){
bitset<20> bin(s);
return bin.to_ulong();
}
ll find_next(ll l, ll n){
if ((l - 1) % n == 0) return l - 1;
else return (((l - 1) / n) * n) + n;
}
ll find_prev(ll r, ll n){
return (r / n) * n;
}
bool change_state(bool cond){
if (cond) return false;
else return true;
}
void solve()
{
string s;
cin >> s;
deque<char> track;
for (int i = 0, n = s.size(); i < n; i++){
track.push_back(s[i]);
}
int q;
cin >> q;
bool rev = false;
while(q--){
int type;
cin >> type;
if (type == 1) rev = change_state(rev);
else {
int place;
char c;
cin >> place >> c;
if (!rev){
if (place == 1) track.push_front(c);
else track.push_back(c);
}
else{
if (place == 1) track.push_back(c);
else track.push_front(c);
}
}
}
if (!rev){
while (!track.empty()) {
cout << track.front();
track.pop_front();
}
}
else {
while (!track.empty()){
cout << track.back();
track.pop_back();
}
}
cout << "\n";
}
int main()
{
cin.tie(NULL);
ios_base::sync_with_stdio(false);
// freopen("breedflip.in", "r", stdin);
// freopen("breedflip.out", "w", stdout);
int t;
cin >> t;
for(int i = 1; i <= t; i++)
solve();
return 0;
}