#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;

const int MAX = 10000001;
string ans;

int main(){
	int k;
	scanf("%d", &k);
	string command, s;
	int n;
	bool reversed = false;
	int count = 0;
	while (k--){
		scanf("%d", &n);
		reversed = false;
		ans = "";
		while (n--){
			cin >> command;
			if (command == "end")
				break;
			if (command != "reverse"){
				cin >> s;
				if (reversed)
					ans = s + ans;
				else
					ans = ans + s;
			}
			else
				reversed = !(reversed);
			
		}
		
		if (reversed){
			reverse(ans.begin(), ans.end());
		}
		
		printf("%s\n", ans.c_str());
		
	}
	return 0;
}
