#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
#define rep(l,r,i) for(int i=l;i<r;i++)
#define P pair<int,int>
#define ll long long 

typedef string::const_iterator State;
class ParseError{};

int number(State &begin);
int factor(State &begin);
int term(State &begin);
int expression(State &begin);


int number(State &begin){
    int ret=0;

    while(isdigit(*begin)){
        ret*=10;
        ret+=*begin-'0';
        begin++;
    }

    return ret;
}

int factor(State &begin){
    int ret=0;

    if(*begin=='('){
        begin++;
        ret=expression(begin);
        begin++;
    }
    else{
        ret=number(begin);
    }
    return ret;
}

int term(State &begin){
    int ret=factor(begin);

    for(;;){
        if(*begin=='*'){
            begin++;
            ret*=factor(begin);
        }
        else if(*begin=='/'){
            begin++;
            ret/=factor(begin);
        }
        else{
            break;
        }
    }
    return ret;
}



int expression(State &begin){
    int ret=term(begin);

    for(;;){
        if(*begin=='+'){
            begin++;
            ret+=term(begin);
        }
        else if(*begin=='-'){
            begin++;
            ret-=term(begin);
        }
        else{
            break;
        }
    }
    return ret;
}

int main(){

    int n;
    cin>>n;
    cin.ignore();
    for(int i=0;i<n;i++){
        string s;
        getline(cin,s);
        State begin=s.begin();
        cout<<expression(begin)<<endl;
    }
    return 0;
}
