def divide(x, y):

    s = 1

    if(x < 0):s *= -1

    if(y < 0):s *= -1

    return abs(x) / abs(y) * s     



operator = {"+":(lambda x,y: x+y),

            "-":(lambda x,y: x-y),

            "*":(lambda x,y: x*y),

            "/":divide

            }



def ind(src, x):

    if x not in src:return 1<<30

    return src.index(x)

 

def _split(_src):

    c = 0

    l = len(_src)

    if l == 0:

        return []

    while c < l and ord('0') <= ord(_src[c]) <= ord('9'):

        c += 1



    if c == 0:

        return [_src[0]] + _split(_src[1:])

    else:

        return [int(_src[:c])] + _split(_src[c:])

         

 

def evaluate(src):

    if len(src) == 1:

        return src[0]

         

    if "(" in src:

        l = src.index("(")

        r = l

        st = 1

        while st:

            r += 1

            if src[r] == "(": st += 1

            if src[r] == ")": st -= 1

        

        mid = evaluate(src[l + 1:r])

        return evaluate( src[:l] + [mid] + src[r + 1:])

    

    if "*" in src or "/" in src:

        pos = min(ind(src, "*"), ind(src,"/"))

        op = src[pos]

        l, r = src[pos - 1], src[pos + 1]

        mid = operator[op](l, r)

        return evaluate(src[:pos - 1] + [mid] + src[pos + 2:])

    

    else:

        pos = min(ind(src, "+"), ind(src, "-"))

        op = src[pos]

        l, r = src[pos - 1], src[pos + 1]

        mid = operator[op](l, r)

        return evaluate(src[:pos - 1] + [mid] + src[pos + 2:])

     

for t in range(eval(input())):

    _src = input().strip("=")

    src = _split(_src)

    print(evaluate(src))
def divide(x, y):

    s = 1

    if(x < 0):s *= -1

    if(y < 0):s *= -1

    return abs(x) / abs(y) * s     



operator = {"+":(lambda x,y: x+y),

            "-":(lambda x,y: x-y),

            "*":(lambda x,y: x*y),

            "/":divide

            }



def ind(src, x):

    if x not in src:return 1<<30

    return src.index(x)

 

def _split(_src):

    c = 0

    l = len(_src)

    if l == 0:

        return []

    while c < l and ord('0') <= ord(_src[c]) <= ord('9'):

        c += 1



    if c == 0:

        return [_src[0]] + _split(_src[1:])

    else:

        return [int(_src[:c])] + _split(_src[c:])

         

 

def evaluate(src):

    if len(src) == 1:

        return src[0]

         

    if "(" in src:

        l = src.index("(")

        r = l

        st = 1

        while st:

            r += 1

            if src[r] == "(": st += 1

            if src[r] == ")": st -= 1

        

        mid = evaluate(src[l + 1:r])

        return evaluate( src[:l] + [mid] + src[r + 1:])

    

    pos = min(ind(src, "*"), ind(src,"/"))

    if(pos == 1<<30):

        pos = min(ind(src, "+"), ind(src, "-"))

    op = src[pos]

    l, r = src[pos - 1], src[pos + 1]

    mid = operator[op](l, r)

    return evaluate(src[:pos - 1] + [mid] + src[pos + 2:])



     

for t in range(eval(input())):

    _src = input().strip("=")

    src = _split(_src)

    print(evaluate(src))
def divide(x, y):
    s = 1
    if x < 0:
        s *= -1
    if y < 0:
        s *= -1
    return abs(x) / abs(y) * s


operator = {
    "+": (lambda x, y: x + y),
    "-": (lambda x, y: x - y),
    "*": (lambda x, y: x * y),
    "/": divide,
}


def ind(src, x):
    if x not in src:
        return 1 << 30
    return src.index(x)


def _split(_src):
    c = 0
    l = len(_src)
    if l == 0:
        return []
    while c < l and ord("0") <= ord(_src[c]) <= ord("9"):
        c += 1
    if c == 0:
        return [_src[0]] + _split(_src[1:])
    else:
        return [int(_src[:c])] + _split(_src[c:])


def evaluate(src):
    if len(src) == 1:
        return src[0]
    if "(" in src:
        l = src.index("(")
        r = l
        st = 1
        while st:
            r += 1
            if src[r] == "(":
                st += 1
            if src[r] == ")":
                st -= 1
        mid = evaluate(src[l + 1 : r])
        return evaluate(src[:l] + [mid] + src[r + 1 :])
    if "*" in src or "/" in src:
        pos = min(ind(src, "*"), ind(src, "/"))
        op = src[pos]
        l, r = src[pos - 1], src[pos + 1]
        mid = operator[op](l, r)
        return evaluate(src[: pos - 1] + [mid] + src[pos + 2 :])
    else:
        pos = min(ind(src, "+"), ind(src, "-"))
        op = src[pos]
        l, r = src[pos - 1], src[pos + 1]
        mid = operator[op](l, r)
        return evaluate(src[: pos - 1] + [mid] + src[pos + 2 :])


for t in range(eval(input())):
    _src = input().strip("=")
    src = _split(_src)
    print(evaluate(src))

def divide(x, y):
    s = 1
    if x < 0:
        s *= -1
    if y < 0:
        s *= -1
    return abs(x) / abs(y) * s


operator = {
    "+": (lambda x, y: x + y),
    "-": (lambda x, y: x - y),
    "*": (lambda x, y: x * y),
    "/": divide,
}


def ind(src, x):
    if x not in src:
        return 1 << 30
    return src.index(x)


def _split(_src):
    c = 0
    l = len(_src)
    if l == 0:
        return []
    while c < l and ord("0") <= ord(_src[c]) <= ord("9"):
        c += 1
    if c == 0:
        return [_src[0]] + _split(_src[1:])
    else:
        return [int(_src[:c])] + _split(_src[c:])


def evaluate(src):
    if len(src) == 1:
        return src[0]
    if "(" in src:
        l = src.index("(")
        r = l
        st = 1
        while st:
            r += 1
            if src[r] == "(":
                st += 1
            if src[r] == ")":
                st -= 1
        mid = evaluate(src[l + 1 : r])
        return evaluate(src[:l] + [mid] + src[r + 1 :])
    pos = min(ind(src, "*"), ind(src, "/"))
    if pos == 1 << 30:
        pos = min(ind(src, "+"), ind(src, "-"))
    op = src[pos]
    l, r = src[pos - 1], src[pos + 1]
    mid = operator[op](l, r)
    return evaluate(src[: pos - 1] + [mid] + src[pos + 2 :])


for t in range(eval(input())):
    _src = input().strip("=")
    src = _split(_src)
    print(evaluate(src))

-    if "*" in src or "/" in src: -        pos = min(ind(src, "*"), ind(src, "/")) -        op = src[pos] -        l, r = src[pos - 1], src[pos + 1] -        mid = operator[op](l, r) -        return evaluate(src[: pos - 1] + [mid] + src[pos + 2 :]) -    else: +    pos = min(ind(src, "*"), ind(src, "/")) +    if pos == 1 << 30: -        op = src[pos] -        l, r = src[pos - 1], src[pos + 1] -        mid = operator[op](l, r) -        return evaluate(src[: pos - 1] + [mid] + src[pos + 2 :]) +    op = src[pos] +    l, r = src[pos - 1], src[pos + 1] +    mid = operator[op](l, r) +    return evaluate(src[: pos - 1] + [mid] + src[pos + 2 :])