#include<iostream>
#include<string>
#include<cstdio>
#include<cassert>
using namespace std;
string S;
int cur=0;
int factor();
bool isdigit();
int number();
int term();
int expression();
int main(){
  int n;
  cin>>n;
  while(n--){
    cin>>S;
    cur=0;
    cout<<expression()<<endl;
  }
}

bool isdigit(){
  return '0'<=S[cur]&&S[cur]<='9';
}
int digit(){
  assert(isdigit());
  int ret=(int)(S[cur]-'0');
  cur++;
  return ret;
}
int number(){
  int ret=1;
  while(!isdigit()){
    ret=(S[cur]=='-')?-1:1;
    cur++;
  }
  ret*=digit();
  while(isdigit()){
    ret=ret*10+digit();
  }
  return ret;
}

int factor(){
  int ret=0;
  if(S[cur]=='('){
    cur++;
    ret=expression();
    cur++;//')'
  }else{
    ret=number();
  }
  return ret;
}
int term(){
  int ans=factor();
  while(cur<(int)S.size()-1&&S[cur]!='+'&&S[cur]!='-'&&S[cur]!=')'){
    char op=S[cur];
    cur++;
    int right=factor();
    //cout<<"TERMop=="<<op<<" "<<right<<endl;
    switch(op){
    case '*':
      ans*=right;
      break;
    case '/':
      ans/=right;
      break;
    default ://///
      break;
    } 
  }
  return ans;
}
int expression(){
  int ans=term();
  while(cur<(int)S.size()-1&&S[cur]!=')'){
    char op=S[cur];
    cur++;
    int right=term();
    //cout<<"EXop=="<<op<<" "<<right<<endl;
    switch(op){
    case '+':
      ans+=right;
      break;
    case '-':
      ans-=right;
      break;
    default ://///
      break;
    } 
  }
  return ans;
}