#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

string toRPN(string s){
    stack<char> ope;
    string ret;
    int len=s.size();
    
    for(int i=0;i<len;i++){
        if( isdigit(s[i]) ) ret+=s[i];
        
        else{
            if(s[i]=='('){
                ope.push(s[i]);
                
            }else if(s[i]==')'){
                while(ope.top()!='('){
                    ret+=ope.top();
                    ope.pop();
                }
                ope.pop();
                
            }else if( s[i]=='*' || s[i]=='/' ){
                while( !ope.empty() && (ope.top()=='*' || ope.top()=='/') ){
                    ret+=ope.top();
                    ope.pop();
                }
                ope.push(s[i]);
                
            }else if( s[i]=='+' || s[i]=='-' ){
                while( !ope.empty() && (ope.top()=='*' || ope.top()=='/' || ope.top()=='+' || ope.top()=='-') ){
                    ret+=ope.top();
                    ope.pop();
                }
                ope.push(s[i]);
                
            }else{
                return "invalid";
            }
        }
    }
    while(ope.size()){
        ret+=ope.top();
        ope.pop();
    }

    return ret;
}


string solveRPN(string s){
    stack<int> stk;

    
    for(int i=0;i<s.size();i++){
        if( isdigit(s[i]) )stk.push( s[i]-'0'  );
        else{
            int b=stk.top(); stk.pop();
            int a=stk.top(); stk.pop();
            
            if(s[i]=='+')stk.push(a+b);
            if(s[i]=='-')stk.push(a-b);
            if(s[i]=='*')stk.push(a*b);
            if(s[i]=='/')stk.push(a/b);
        }
    }
    
    stringstream ret;
    ret<<stk.top();
    
    return ret.str();
}


int main(){
    int n;
    cin>>n;
    rep(i,n){
        string s;
        cin>>s;
        
        s.erase(s.size()-1);
        
        s=toRPN(s);
        s=solveRPN(s);
    
        cout<<s<<endl;
    }
    
    return 0;
}