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

using namespace std;

string S;
size_t cur=0;
int n;
void init_S(){
    cur=0;
    
}
char readchar(){
    assert(cur<S.size());
    char ret=S[cur];
    cur+=1;
    return ret;
}
char peek(){
    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 factor();
int term(){
    int sum=factor();
    while(cur<S.size()&&(peek()=='*'||peek()=='/')){
        char op=readchar();
        int b=factor();
        if(op=='*')sum*=b;
        else sum/=b;
    }
    return sum;
}
int b;

int expression(){
    int sum=term();
    while(cur<S.size() && (peek()=='+'||peek()=='-')){
        char op=readchar();
        int b=term();
        if(op=='+')sum+=b;
        else sum-=b;
    }
    return sum;
}
           
int factor(){
    if(peek()!='('){
        return number();
    }
    cur++;
    int n=expression();
    assert(peek()==')');
    cur++;
    return n;
}

int parse(){
    return expression();
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>S;
        int a=parse();
        cout<<a<<endl;
        S.clear();
        init_S();
    }
    return 0;
}

