#include <iostream>
#include <cctype>
#include <cassert>
using namespace std;

string S;
int cur;
int expression();
char readerchar()
{
    assert(cur < S.size());
    char ret = S[cur];
    cur += 1;
    return ret;
}
char peek()
{
    assert(cur < S.size());
    return S[cur];
}
int digit()
{
    assert(isdigit(peek()));
    int n = readerchar() - '0';
    return n;
}
int number()
{
    int n=digit();
    while(cur<S.size() && isdigit(peek()))
        n = n*10 + digit();
    return n;
}
int factor()
{
    if(peek()!='(')
        return number();
    cur += 1;
    int n = expression();
    assert(peek() == ')');
    cur += 1;
    return n;
}
int term()
{
    int a = factor();
    while(cur < S.size() && (peek()=='*' || peek()=='/'))
    {
        char op = readerchar();
        int b = factor();
        if(op == '*')
            a *= b;
        else    a /= b;
    }
    return a;
}
int expression()
{
    int a = term();
    while(cur < S.size() && (peek()=='+' || peek()=='-'))
    {
        char op = readerchar();
        int b = term();
        if(op == '+')
            a += b;
        else
            a -= b;
    }
    return a;
}


int main()
{
    int n,i;
    cin >> n;
    for(i=0;i<n;i++)
    {
        cur = 0;
        cin >> S;
        S.resize(S.size()-1);
        cout << expression() << endl;
    }
    return 0;
}
