#include<iostream>
#include<vector>
using namespace std;

int solve(string str){
    vector<int>op;
    vector<char>ope;
    //cout<<"str: "<<str<<endl;
    //cout<<str.length()<<endl;
    for(int i=0;i<str.length();i++){
        //cout<<"KK";
        if(str[i]=='('){
            string t;
            i++;
            while(str[i]!=')'){
                t+=str[i];
                i++;
            }
            i++;
            op.push_back(solve(t));
            //cout<<"(): "<<ope[ope.size()-1]<<endl;
            if(ope.size())
            if(ope[ope.size()-1]=='*'||ope[ope.size()-1]=='/'){
                int a=op[op.size()-1];
                op.pop_back();
                int b=op[op.size()-1];
                op.pop_back();
                if(ope[ope.size()-1]=='*')op.push_back(a*b);
                else op.push_back(b/a);
                ope.pop_back();
            }
            ope.push_back(str[i]);
        }
        else if(str[i]>='0'&&str[i]<='9'){
            int g=0;
            while(str[i]>='0'&&str[i]<='9'){
                g=g*10+str[i]-'0';
                i++;
            }
            op.push_back(g);
            if(ope.size())
                if(ope[ope.size()-1]=='*'||ope[ope.size()-1]=='/'){
                    int a=op[op.size()-1];
                    op.pop_back();
                    int b=op[op.size()-1];
                    op.pop_back();
                    if(ope[ope.size()-1]=='*')op.push_back(a*b);
                    else op.push_back(b/a);
                    ope.pop_back();
                }
            if(str[i])ope.push_back(str[i]);
        }
    }
    //cout<<"!"<<endl;
    int las=op[op.size()-1];
    op.pop_back();
    while(ope.size()){
        //cout<<"las: "<<las<<endl;
        char c=ope[ope.size()-1];
        ope.pop_back();
        if(c=='=')continue;
        int pre=op[op.size()-1];
        //cout<<"pre: "<<pre<<endl;
        //cout<<ope.size()<<"   c: "<<c<<endl;
        op.pop_back();
        if(c=='+')las=las+pre;
        else las=pre-las;
    }
    //cout<<"returned : "<<las<<endl;
    return las;
}

int main(){
    int n;
    cin>>n;
    while(n--){
        string str;
        cin>>str;
        cout<<solve(str)<<endl;
    }
}