import std.stdio,  std.string,  std.conv,  std.ascii,  std.array;

void main()
{
    foreach(_; 0 .. readln.chomp.to!int)
    {
        line = readln.chomp;
        add.writeln;

    }
}

string line;

int add()
{
    int lhs  =  mul;
    loop:
    while(true)
    {
        switch(line[0])
        {
            case '+':
                line.popFront;
                lhs += mul;
                break;
            case '-':
                line.popFront;
                lhs -= mul;
                break;
            default:
                break loop;
        }
    }
    return lhs;
}

int mul()
{
    int lhs = prim;
    loop:
    while(true)
    {
        switch(line[0])
        {
            case '*':
                line.popFront;
                lhs *= prim;
                break;
            case '/':
                line.popFront;
                lhs /= prim;
                break;
            default:
                break loop;
        }
    }
    return lhs;
}

int prim()
{
    int r;
    if(line[0] == '(')
    {
        line.popFront;
        r = add;
        line.popFront;
    }
    else if(line[0] == '-')
    {
        line.popFront;
        r = -mul;

    }
    else while(line[0] != '=')
    {
        if(line[0].isDigit)
        {
            r  =  r * 10 + (line[0] - '0');
            line.popFront;
        } 
        else break;
    }
    return r;
}