SPOJ ONP
prograM onp;
const
os='+-*/^()#';
w:array [1..8] of string[8]=('>><<<<>>',
'>><<<<>>',
'>>>><<>>',
'>>>><<>>',
'>>>>><>>',
'<<<<<<= ',
'>>>>> >>',
'<<<<<< =');
var
s:ansistring;
c:char;
i,t,r,op,np:integer;
o:array [1..402] of char;
n:array [1..402] of ansistring;
procedure process;
begin
np:=0; op:=1; o[1]:='#';
r:=1; s:=s+'#';
while (s[r]<>'#') or (o[op]<>'#') do
begin
if pos(s[r],os)=0 then
begin inc(np); n[np]:=s[r]; inc(r); continue end;
c:=w[pos(o[op],os)][pos(s[r],os)];
if c='<' then
begin inc(op); o[op]:=s[r]; inc(r); end;
if c='=' then
begin dec(op); inc(r) end;
if c='>' then
begin dec(np); n[np]:=n[np]+n[np+1]+o[op]; dec(op); end;
end;
writeln(n[np]);
end;
begin
readln(t);
for i:=1 to t do
begin
readln(s);
process
end;
end.