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 = -prim;
    }
    else
    {
        int i;
        while(line[i].isDigit) ++i;
        r = line[0 .. i].to!int;
        line = line[i .. $];
    }
    return r;
}