#include <iostream>
//#define int long long
//#define _DEBUG
//#include <vector>
#include <string>
//#include <map>
//#include <stack>
#include <cassert>
using namespace std;

//input
int N;
string input;

int cur;
int expression();

char readchar(){
    assert(cur < input.size());
    return input[cur++];
}
char peek(){
    assert(cur < input.size());
    return input[cur];
}
bool isDisit(char c){
    return int(c)>=48 && int(c)<58;
}
int disit(){
    assert(isDisit(peek()));
    return readchar() - '0';
}
int number(){
    int n = disit();
    while(cur < input.size() && isDisit(peek())){
        n = 10*n + disit();
    }
    return n;
}
char additiveOpr(){
    assert(peek()=='+' || peek()=='-');
    return readchar();
}
char multiveOpr(){
    assert(peek()=='*' || peek()=='/');
    return readchar();
}
int opr(char opr, int x, int y){
    if(opr=='+'){
        return x+y;
    }else if(opr=='-'){
        return x-y;
    }else if(opr=='*'){
        return x*y;
    }else if(opr=='/'){
        assert(y!=0);
        return x/y;
    }else{
        return -1;//error
    }
}
int factor(){
    if(peek()!='(') return number();
    cur++;
    int n = expression();
    assert(peek()==')');
    cur++;
    return n;
}
int term(){
    int r = factor();
    while(cur<input.size()
            &&(peek()=='*' || peek()=='/')){
        char o = multiveOpr();
        int b = factor();
        r = opr(o,r,b);
    }
    return r;
}
int expression(){
    int r = term();
    while(cur<input.size() 
            &&(peek()=='+' || peek()=='-')){
        char o = additiveOpr();
        int b = term();
        r = opr(o,r,b);
    }
    return r;
}
int solve(){
    int n = expression();
    assert(peek()=='=');
    return n;
}
signed main(){
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> input;
        cur = 0;
        cout << solve() << endl;
    }
}
