#include<iostream>
#include<cassert>
#include <string>
#include <cctype>

using namespace std;

#if 0
所用時間:

感想:

#endif

string S;
size_t cur;

int expression();
int factor();

char readchar(){
    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 = readchar() - '0';
    return n;
}

int number(){
    int n = digit();
    while( cur < S.size() && isdigit(peek()))
        n = n * 10 + digit();
    return n;
}

int term(){
    int a = factor();
    while(cur < S.size() && (peek()=='*' || peek()=='/')){
        char op = readchar();
        int b = factor();
        if(op=='*') a*= b;
        else a /= b;
        cout << "calc: " << a << " " << op << " " << b << endl;
    }
    return a;
}

int factor(){
    if (peek() == '('){
        cur += 1;
        int n = expression();
        assert(peek() == ')');
        cur += 1;
        return n;
        }
    else return number();
}

int expression(){
    int a = term();
    while(cur < S.size() && (peek()=='+' || peek()=='-')){
        char op = readchar();
        int b = term();
        cout << "calc: " << a << " " << op << " " << b << endl;
        if(op == '+'){
            a += b;
        }else{
            a -= b;
            }
    }
    return a;
}


int parse(){
    return expression();
}

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> S;
        cur = 0;
        S.resize(S.size()-1); // 最後の=を無視
        int a = parse();
        cout << a << endl;
    }
}

