import java.util.*;
import java.lang.*;
import java.io.*;
class Index {
int in;
public Index(int a) {
in = a;
}
}
class Main
{
public static void get_levels
(char[] Expr, Index index,
int depth,
String[] Answer
) { Answer[depth] += Expr[index.in];
index.in--;
if (Character.
isUpperCase(Expr
[index.
in + 1])) { get_levels(Expr, index, depth + 1, Answer);
get_levels(Expr, index, depth + 1, Answer);
}
}
{
Scanner in
= new Scanner
(System.
in); int n = in.nextInt();
for (int k = 0; k < n; k++) {
str = in.next();
char[] Expr = str.toCharArray();
Index index = new Index(Expr.length - 1);
get_levels(Expr, index, 0, Answer);
for (int j = Expr.length - 1; j >= 0; j--)
}
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpjbGFzcyBJbmRleCB7CglpbnQgaW47CglwdWJsaWMgSW5kZXgoaW50IGEpIHsKCQlpbiA9IGE7Cgl9Cn0KCmNsYXNzIE1haW4KewoJcHVibGljIHN0YXRpYyB2b2lkIGdldF9sZXZlbHMoY2hhcltdIEV4cHIsIEluZGV4IGluZGV4LCBpbnQgZGVwdGgsIFN0cmluZ1tdIEFuc3dlcikgewoJCUFuc3dlcltkZXB0aF0gKz0gRXhwcltpbmRleC5pbl07CgkJaW5kZXguaW4tLTsKCQlpZiAoQ2hhcmFjdGVyLmlzVXBwZXJDYXNlKEV4cHJbaW5kZXguaW4gKyAxXSkpIHsKCQkJZ2V0X2xldmVscyhFeHByLCBpbmRleCwgZGVwdGggKyAxLCBBbnN3ZXIpOwoJCQlnZXRfbGV2ZWxzKEV4cHIsIGluZGV4LCBkZXB0aCArIDEsIEFuc3dlcik7CgkJfQoJfQoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBqYXZhLmxhbmcuRXhjZXB0aW9uCgl7CgkJU2Nhbm5lciBpbiA9IG5ldyBTY2FubmVyKFN5c3RlbS5pbik7CgkJaW50IG4gPSBpbi5uZX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