#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){

  int n;
  int data[30][2];
  int now_train;

  cin>> n;
  while(n--){
    for(int i=0;i<26;i++) data[i][0]=data[i][1]=-1;
    char c;
    cin>> c;
    now_train=abs('a'-c);
    
    string s;
    cin>> s;
    for(int i=0;i<s.size();i+=3){
      if(s[i]=='-'){
	data[now_train][1]=abs('a'-s[i+2]);
	data[abs('a'-s[i+2])][0]=now_train;
      }
      else{
	data[now_train][0]=abs('a'-s[i+2]);
	data[abs('a'-s[i+2])][1]=now_train;
      }
      now_train=abs('a'-s[i+2]);
    }
    
    string ans;
    int left,right;
    for(int i=0;i<26;i++){
      if(data[i][0]==-1 && data[i][1]!=-1){
	left=i;
	ans+='a'+left;
      }
      else if(data[i][1]==-1 && data[i][0]!=-1){
	right=i;
      }
    }
    while(left!=right){
      ans+='a'+data[left][1];
      left=data[left][1];
    }
    cout<< ans<< endl;
  }
}