import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.*;
public class Main {
static Boolean DEBUG = false;
static int maxi = 0;
static int n = 0;
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
for(int i=0 ; i<n ; i++) {
List<Character> ll = new LinkedList<>();
int idx = 0;
String s = br.readLine();
int sidx = 0;
for(int j=0 ; j<s.length(); j++) {
char t = s.charAt(j);
if(t == '<' ) {
if(sidx !=0 ) {
sidx--;
}
continue;
}
else if(t == '>' ) {
if( (sidx != ll.size() ) ) {
sidx++;
}
continue;
}
else if(t == '-') {
if(sidx == 0 || ll.size()==0) {
continue;
}
ll.remove(sidx-1);
sidx--;
continue;
}else {
ll.add(sidx,t);
sidx++;
}
}
StringBuilder sb = new StringBuilder();
for(char c : ll) {
sb.append(c);
}
sb.append("\n");
bw.write(sb.toString());
}
bw.flush();
bw.close();
}
}