#include <bits/stdc++.h>
using namespace std;
int p;
string s;
int number();
int factor();
int term();

int expression(){
    int num=term();
    while(s.size()>p){
        if(s[p]=='+'){
            p++;
            num+=term();
        }else if(s[p]=='-'){
            p++;
            num-=term();
        }else{
            break;
        }
    }
    return num;
}

int term(){
    int num=factor();
    while(s.size()>p){
        if(s[p]=='*'){
            p++;
            num*=factor();
        }else if(s[p]=='/'){
            p++;
            num/=factor();
        }else{
            break;
        }
    }
    return num;
}

int factor(){
    int num;
    if(s.size()>p and s[p]=='('){
        p++;
        num=expression();
        p++;
    }else{
        return number();
    }
    return num;
}

int number(){
    int num=0;
    while(s.size()>p and isdigit(s[p])){
        num*=10;
        num+=s[p]-'0';
        p++;
    }
    return num;
}

int main(void){
    int n,i;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>s;
        p=0;
        cout<<expression()<<endl;
    }
}

