#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cctype>
#include <cassert>

using namespace std;

string str;
int cnt;

int digit(){
    assert(isdigit(str[cnt]));
    int n=str[cnt++]-'0';
    return n;
}
int number(){
    int n=digit();
    while(cnt<str.size()&&isdigit(str[cnt])){
        n*=10;
        n+=digit();
    }
    return n;
}
int term(void);
int fact(void);

int exp(void){
    int s0=term();
    while(cnt<str.size()){
        char op=str[cnt];
        if(op!='+'&&op!='-')
            break;
        cnt++;
        int s1=term();
        switch(op){
            case '+':
                s0+=s1;
                break;
            case '-':
                s0-=s1;
                break;
            default:
                assert(0);
        }
    }
    return s0;
}
int term(void){
    int s0=fact();
    while(cnt<str.size()){
        char op=str[cnt];
        if(op!='*'&&op!='/')
            break;
        cnt++;
        int s1=fact();
        switch(op){
            case '*':
                s0*=s1;
                break;
            case '/':
                s0/=s1;
                break;
            default:
                assert(0);
        }
    }
    return s0;
}

int fact(void){
    if(str[cnt]=='('){
        cnt++;
        int n=exp();
        assert(str[cnt]==')');
        cnt++;
        return n;
    }
    return number();
}

int main(void){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>str;
        cnt=0;
        cout<<exp()<<endl;
    }
}