There are trains with 26 cars or less. Each vehicle has an identification code from lowercase a to z. No vehicle has the same symbol. However, the order in which the vehicles are connected is arbitrary. The conductor patrols the train. The conductor patrolls back and forth in the train, so he may pass through the same vehicle many times. However, all vehicles shall be patrolled at least once. In addition, the vehicle that starts the patrol and the vehicle that finishes the patrol is not necessarily the vehicle at the end of the train.

There is a patrol record of all the trains on which an Aru Shashou is on board. Create a program that outputs the formation of each train that can be seen from it from the lead car. The patrol record corresponds to one train per line. Each line consists of a string of lowercase letters separated by <-or->. <-Represents a move to a vehicle in front, and-> represents a move to a vehicle behind.

For example, a-> b <-a <-c means that vehicle a has moved to the vehicle behind b, b has moved to a ahead, and a has moved to c ahead. In this case, the train formation will be cab from the first car.



Input

The number of patrol records n (n ≤ 50) is given to the first line, and the character string si (half-width character string up to 1024 characters) representing the patrol record i is given to the following n lines.

Output

For patrol record i, output the character string indicating the formation of the train from the first car on the i-line.

Examples

Input

4
a->e->c->b->d
b


Output

aecbd
edacb
bacde
bcdae


Input

4
a->e->c->b->d
b<-c<-a<-d<-e
b->a->c<-a->c->d<-c<-a<-b->a->c->d->e<-d
a->e<-a<-d->a->e<-a<-d<-c->d->a<-d<-c<-b->c->d<-c


Output

aecbd
edacb
bacde
bcdae

Source: aizu | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
for _ in range(int(input())):
	s = list(input())
	(word, direct) = ([], '')
	for i in s:
		if i.isalpha():
			if direct == '>':
				if i not in word:
					word.append(i)
			elif i not in word:
				word.insert(0, i)
		elif i == '<' or i == '>':
			direct = i
	print(*word, sep='')


n = int(input())
for i in range(n):
	s = input()
	station_list = []
	for si in s[::3]:
		station_list.append(si)
	st_l = list(dict.fromkeys(station_list))
	ans = [0] * 51
	ans[25] = station_list[0]
	for j in st_l[1:]:
		place = s.index(j)
		now = s[place - 3:place + 1]
		if now[1:3] == '->':
			ans[ans.index(now[0]) + 1] = now[3]
		elif now[1:3] == '<-':
			ans[ans.index(now[0]) - 1] = now[3]
	ans_l = list(dict.fromkeys(ans))
	ans_l.remove(0)
	print(''.join(map(str, ans_l)))


n = int(input())
for i in range(n):
	s = input()
	train = [s[0]]
	for i in range(1, len(s), 3):
		ind = train.index(s[i - 1])
		if s[i:i + 2] == '->' and s[i + 2] not in train:
			train.insert(ind + 1, s[i + 2])
		elif s[i:i + 2] == '<-' and s[i + 2] not in train:
			train.insert(ind, s[i + 2])
	print(''.join(train))


n = int(input())
for _ in range(n):
	s = input()
	rec = [None] * 52
	ind = 25
	rec[ind] = s[0]
	max_ind = 25
	min_ind = 25
	for i in range(1, len(s), 3):
		direct = s[i:i + 2]
		if direct == '->':
			ind += 1
			max_ind = max(ind, max_ind)
		else:
			ind -= 1
			min_ind = min(ind, min_ind)
		rec[ind] = s[i + 2]
	print(''.join(rec[min_ind:max_ind + 1]))


for _ in range(int(input())):
	s = list(input())
	(ans, dir) = ([], '>')
	for x in s:
		if x.isalpha():
			if dir == '>':
				if x not in ans:
					ans.append(x)
			elif x not in ans:
				ans.insert(0, x)
		elif x == '>' or x == '<':
			dir = x
	print(*ans, sep='')


import sys
from sys import stdin
input = stdin.readline
from collections import deque

def bfs(u, result, out_edge, in_degree, processed):
	q = deque()
	q.append(u)
	processed[u] = True
	while q:
		u = q.popleft()
		result.append(u)
		for e in out_edge[u]:
			in_degree[e] -= 1
			if in_degree[e] == 0 and processed[e] == False:
				processed[e] = True
				q.append(e)

def solve(V, in_degree, out_edge):
	result = []
	processed = [False for _ in range(V)]
	for (i, u) in enumerate(in_degree):
		if u == 0 and processed[i] == False:
			bfs(i, result, out_edge, in_degree, processed)
	return result

def decode_txt(S):
	es = set()
	cars = set()
	l = len(S)
	for i in range(l):
		if not 'a' <= S[i] <= 'z':
			continue
		s = S[i]
		try:
			t = S[i + 3]
		except IndexError:
			break
		cars.add(s)
		cars.add(t)
		if S[i + 1] == '-':
			es.add((s, t))
		else:
			es.add((t, s))
	return (es, cars)

def main(args):
	n = int(input())
	for _ in range(n):
		S = input().strip()
		if len(S) < 4:
			print(S)
			continue
		(es_txt, cars) = decode_txt(S)
		V = len(cars)
		num = 0
		mapping = dict()
		for c in cars:
			mapping[c] = num
			num += 1
		rev_mapping = dict(zip(mapping.values(), mapping.keys()))
		es = []
		for (s, t) in es_txt:
			es.append([mapping[s], mapping[t]])
		in_degree = [0 for _ in range(V)]
		out_edge = [[] for _ in range(V)]
		for (s, t) in es:
			out_edge[s].append(t)
			in_degree[t] += 1
		result = solve(V, in_degree, out_edge)
		txt = [rev_mapping[x] for x in result]
		print(''.join(txt))
main(sys.argv[1:])


n = int(input())
for i in range(0, n):
	datas = input()
	dic = dict()
	sIndex = inIndex = isMove = 0
	while sIndex < len(datas):
		if not isMove:
			dic[datas[sIndex]] = inIndex
			sIndex += 2
		else:
			if datas[sIndex] == '>':
				inIndex += 1
			else:
				inIndex -= 1
			sIndex += 1
		isMove = not isMove
	dic = {k: v for (k, v) in sorted(dic.items(), key=lambda item: item[1])}
	for k in dic.keys():
		print(k, end='')
	print()


inputCount = int(input())
for _ in range(inputCount):
	inputContent = input()
	trainOrder = [item for item in inputContent if str.isalpha(item)]
	directOrder = [item for item in inputContent if item == '<' or item == '>']
	trainList = []
	trainList.append(trainOrder[0])
	listIndex = 1
	trainLength = 1
	for (train, direct) in zip(trainOrder[1:], directOrder):
		if listIndex == 1 and direct == '<':
			trainList.insert(0, train)
			trainLength += 1
		elif listIndex == trainLength and direct == '>':
			trainList.append(train)
			listIndex += 1
			trainLength += 1
		elif direct == '<':
			listIndex -= 1
		elif direct == '>':
			listIndex += 1
	output = ''.join(trainList)
	print(output)


for _ in range(int(input())):
	s = list(input())
	ans = []
	dir = '>'
	for i in range(len(s)):
		if s[i].isalpha():
			if dir == '>':
				if s[i] not in ans:
					ans.append(s[i])
			elif s[i] not in ans:
				ans.insert(0, s[i])
		elif s[i] == '>' or s[i] == '<':
			dir = s[i]
	print(*ans, sep='')


n = int(input())
for _ in range(n):
	record = input()
	record = list(record)
	ans = [record.pop(0)]
	while record != []:
		arrow = record.pop(0)
		record.pop(0)
		train = record.pop(0)
		if train not in ans:
			if arrow == '-':
				ans.append(train)
			else:
				ans.insert(0, train)
	print(''.join((str(a) for a in ans)))


n = int(input())
for _ in range(n):
	train = ''
	seq = input()
	for i in range(0, len(seq), 3):
		if i == 0:
			train += seq[i]
		if seq[i - 2:i] == '->' and train[-1] == seq[i - 3]:
			train = train + seq[i]
		if seq[i - 2:i] == '<-' and train[0] == seq[i - 3]:
			train = seq[i] + train
	print(train)


I = input
for _ in [0] * int(I()):
	t = I()
	a = t[0]
	for x in range(1, len(t), 3):
		if t[x + 2] in a:
			continue
		if t[x] == '-':
			a += t[x + 2]
		else:
			a = t[x + 2] + a
	print(a)


I = input
for _ in [0] * int(I()):
	t = I()
	ans = [t[0]]
	for x in range(1, len(t), 3):
		if t[x + 2] in ans:
			continue
		if t[x] == '-':
			ans += [t[x + 2]]
		else:
			ans = [t[x + 2]] + ans
	print(*ans, sep='')


def proc(i):
	l = len(i)
	o = [i[0]]
	io = 1
	ii = 1
	while ii < l:
		if i[ii:ii + 2] == '<-':
			io -= 1
		else:
			io += 1
		if io == 0:
			o.insert(io, i[ii + 2])
			io += 1
		elif io == len(o) + 1:
			o.insert(io, i[ii + 2])
		elif i[ii + 2] != o[io - 1]:
			raise untimeError('error')
		ii += 3
	s = ''
	for c in o:
		s += c
	return s
n = int(input())
for _ in range(n):
	l = input()
	r = proc(l)
	print(r)


N = int(input())
for l in range(N):
	s = input()
	ans = s[0]
	s = s[1:]
	while s != '':
		dist = s[0:2]
		ss = s[2]
		if not ss in ans:
			if dist == '->':
				ans = ans + ss
			else:
				ans = ss + ans
		s = s[3:]
	print(ans)


inputCount = int(input())
for _ in range(inputCount):
	inputContent = input()
	trainOrder = [item for item in inputContent if str.isalpha(item)]
	directOrder = [item for item in inputContent if item == '<' or item == '>']
	trainList = trainOrder[0]
	listIndex = 1
	trainLength = 1
	for (train, direct) in zip(trainOrder[1:], directOrder):
		if listIndex == 1 and direct == '<':
			trainList = train + trainList
			trainLength += 1
		elif listIndex == trainLength and direct == '>':
			trainList += train
			listIndex += 1
			trainLength += 1
		elif direct == '<':
			listIndex -= 1
		else:
			listIndex += 1
	print(trainList)


num = int(input())
OFFSET = 25
for _ in range(num):
	T = [None] * (25 + 1 + 25)
	s = input()
	t = list(s[0::3])
	d = list(s[2::3])
	for i in range(len(t)):
		if i == 0:
			p = 0
		elif d[i - 1] == '>':
			p += 1
		else:
			p -= 1
		T[p + OFFSET] = t[i]
	for i in T:
		if i:
			print(i, end='')
	print()


for _ in range(int(input())):
	s = input().replace('->', '>').replace('<-', '<')
	(t, train, s) = (s[0], [s[0]], s[1:])
	for i in range(0, len(s), 2):
		if s[i] == '>' and (not s[i + 1] in train):
			idx = train.index(t) + 1
			train.insert(idx, s[i + 1])
		elif not s[i + 1] in train:
			idx = train.index(t)
			train.insert(idx, s[i + 1])
		t = s[i + 1]
	print(''.join(train))


inputCount = int(input())
for _ in range(inputCount):
	inputContent = input()
	trainOrder = [item for item in inputContent if str.isalpha(item)]
	directOrder = [item for item in inputContent if item == '<' or item == '>']
	trainList = []
	trainList.append(trainOrder[0])
	listIndex = 1
	trainLength = 1
	for (train, direct) in zip(trainOrder[1:], directOrder):
		if listIndex == 1 and direct == '<':
			trainList.insert(0, train)
			trainLength += 1
		elif listIndex == trainLength and direct == '>':
			trainList.append(train)
			listIndex += 1
			trainLength += 1
		elif direct == '<':
			listIndex -= 1
		else:
			listIndex += 1
	output = ''.join(trainList)
	print(output)


n = int(input())
for i in range(n):
	Tr = list(input())
	cou = 0
	ans = [Tr[cou]]
	while len(Tr) - 1 > cou:
		if Tr[cou + 1] == '-':
			if Tr[cou + 3] in ans:
				cou += 3
				continue
			else:
				ans = ans + [Tr[cou + 3]]
		elif Tr[cou + 3] in ans:
			cou += 3
			continue
		else:
			ans = [Tr[cou + 3]] + ans
		cou += 3
	a_s = ''
	for i in range(len(ans)):
		a_s = a_s + ans[i]
	print(a_s)


from collections import deque
n = int(input())
for _ in range(n):
	cmd = input()
	A = deque()
	flg = 0
	for y in cmd:
		if y != '-':
			if y == '>':
				flg = 0
			elif y == '<':
				flg = 1
			elif y not in A:
				if flg == 0:
					A.append(y)
				else:
					A.appendleft(y)
	B = ''
	for x in A:
		B += x
	print(B)


n = int(input())
for _ in range(n):
	s = input()
	s = s.replace('-', '')
	train = ['' for i in range(60)]
	pointer = 30
	for i in s:
		if i == '<':
			pointer -= 1
		elif i == '>':
			pointer += 1
		else:
			train[pointer] = i
	print(''.join(train))