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

/*
Digit := '0' | '1' | ... | '9'
Number := Digit { Digit }
Expression := Term { ('+'|'-') Term }
Term := Factor { ('*'|'/') Factor }
Factor := '(' Expression ')' | Number
*/

string S;
size_t cur=0;

int digit();
int number();
int expression();
int term();
int factor();

int digit(){
    assert(isdigit(S[cur]));
    int n=S[cur]-'0';
    cur++;

    return n;
}

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

int expression(){
    int n=term();
    while(cur<S.length() && (S[cur]=='+' || S[cur]=='-')){
        if(S[cur]=='+'){
            cur++;
            n=n+term();
        }else{
            cur++;
            n=n-term();
        }
    }

    return n;
}

int term(){
    int n=factor();
    while(cur<S.length() && (S[cur]=='*' || S[cur]=='/')){
        if(S[cur]=='*'){
            cur++;
            n=n*factor();
        }else{
            cur++;
            n=n/factor();
        }
    }

    return n;
}

int factor(){
    if(S[cur]=='('){
        cur++;
        int n=expression();
        assert(S[cur]==')');
        cur++;

        return n;
    }else{
        return number();
    }
}

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cur=0;
        cin >> S;
        S.resize(S.length()-1);

        cout << expression() << endl;
    }

    return 0;
}