def f1(line):
    p = None
    q = None
    for i, s in enumerate(line):
        if s == '(':
            p = i
        elif s == ')':
            q = i
        if q:
            break
    else:
        return f2(line)
    before = line[:p]
    after = line[q + 1:]
    x = f2(line[p + 1:q])
    return f1(before + str(x) + after)


def f2(f_line):
    foo = []
    digit = ''
    for x in f_line:
        if x.isdigit():
            digit += x
        else:
            foo.append(int(digit))
            foo.append(x)
            digit = ''
    foo.append(int(digit))
    return f3(foo, 'first')


def f3(foo, flg):
    if len(foo) == 1:
        return foo[0]
    target = None
    for i, fo in enumerate(foo):
        if flg == 'first':
            target = f4(foo, fo, i)
        elif flg == 'second':
            target = f5(foo, fo, i)
        if target:
            break
    else:
        flg = 'second'
        return f3(foo, flg)
    foo = foo[:i-1] + [target] + foo[i+2:]
    return f3(foo, flg)


def f4(foo, fo, i):
    target = None
    if fo == '*':
        target = foo[i-1] * foo[i+1]
    elif fo == '/':
        target = int(foo[i-1] / foo[i+1])
    return target


def f5(foo, fo, i):
    target = None
    if fo == '+':
        target = foo[i-1] + foo[i+1]
    elif fo == '-':
        target = foo[i-1] - foo[i+1]
    return target


for _ in range(int(input())):
    ans = f1(input()[:-1])
    print(ans)

### FIXED CODE ###

def up_to_you(formula):
    l_p = None
    r_p = None
    for i, c in enumerate(formula):
        if c == '(':
            l_p = i
        elif c == ')':
            r_p = i
            break
    else:
        print fx(formula)
        return
    
    r = fx(formula[l_p+1:r_p])
    n_formula = formula[:l_p]+r+formula[r_p+1:]
    return up_to_you(n_formula)
            
def fx(gemstone):
    n = ''
    lis = []
    add = ''
    if gemstone[0] == '-':
        gemstone = gemstone[1:]
        add = '-'
    for c in gemstone:
        if c.isdigit():
            n += c
        else:
            if n == '':
                add = '-'
            else:
                lis.append(add+n)
                lis.append(c)
                n = ''
                add = ''
    else:
        lis.append(add+n)
    return isolation(lis)
    
def isolation(lis):
    if len(lis) == 1:
        return str(lis[0])
    o1 = None
    o = None
    o2 = None
    o_i = None
    n_lis = None
    if '*' in lis or '/' in lis:
        for i, v in enumerate(lis):
            if o1 == None:
                o1 = v
            elif v == '*' or v == '/':
                o = v
                o_i = i
            elif v == '+' or v == '-':
                o1 = None
            else:
                o2 = v
                r = discomfort(int(o1), o, int(o2))
                n_lis = lis[:(o_i-1)]+[r]+lis[(o_i+2):]
                return isolation(n_lis)
    else:
        o1 = lis[0]
        o = lis[1]
        o2 = lis[2]
        o_i = 1
        r = discomfort(int(o1), o, int(o2))
        n_lis = lis[:(o_i-1)]+[r]+lis[(o_i+2):]
        return isolation(n_lis)
                
def discomfort(o1, o, o2):
    r = None
    if o == '*':
        r = o1 * o2
    elif o == '/':
        r = o1 / o2
        if o1 < 0 and o1 % o2 != 0: r += 1
    elif o == '+':
        r = o1 + o2
    elif o == '-':
        r = o1 - o2
    return str(r)
    
if __name__ == '__main__':
    N = int(raw_input())
    for i in range(N):
        formula = raw_input().rstrip('=')
        up_to_you(formula)