# Path: tryalgo/our_std.py
# def readint():
#     """
#     function to read an integer from stdin
#     """
#     return int(stdin.readline())
# 
# def readstr():
#     """
#     function to read a string from stdin
#     """
#     return stdin.readline().strip()


from tryalgo.our_std import readint, readstr

    :complexity: linear
    """
    vals = []
    ops = []
    for tok in line_tokens + [';']:
        if tok in PRIORITY:  # tok is an operator
            while (tok != '(' and ops and
                   PRIORITY[ops[-1]] >= PRIORITY[tok]):
                right = vals.pop()
                left = vals.pop()
                vals.append((left, ops.pop(), right))
            if tok == ')':
                ops.pop()    # this is the corresponding '('
            else:
                ops.append(tok)
        elif tok.isdigit():  # tok is an integer
            vals.append(int(tok))
        else:                # tok is an identifier
            vals.append(tok)
    return vals.pop()
# snip}


if __name__ == "__main__":
    # this main program is here to be tested on the online judge
    for test in range(readint()):
        cell = {}
        readstr()                     # consume the empty line
        for _ in range(readint()):

# Path: tryalgo/our_std.py
# def readint():
#     """
#     function to read an integer from stdin
#     """
#     return int(stdin.readline())
# 
# def readstr():
#     """
#     function to read a string from stdin
#     """
#     return stdin.readline().strip()


# Path: tryalgo/arithm_expr_eval.py
from tryalgo.our_std import readint, readstr


    :complexity: linear
    """
    vals = []
    ops = []
    for tok in line_tokens + [';']:
        if tok in PRIORITY:  # tok is an operator
            while (tok != '(' and ops and
                   PRIORITY[ops[-1]] >= PRIORITY[tok]):
                right = vals.pop()
                left = vals.pop()
                vals.append((left, ops.pop(), right))
            if tok == ')':
                ops.pop()    # this is the corresponding '('
            else:
                ops.append(tok)
        elif tok.isdigit():  # tok is an integer
            vals.append(int(tok))
        else:                # tok is an identifier
            vals.append(tok)
    return vals.pop()
# snip}


if __name__ == "__main__":
    # this main program is here to be tested on the online judge
    for test in range(readint()):
        cell = {}
        readstr()                     # consume the empty line
        for _ in range(readint()):

            line = readstr()