#include<iostream>
using namespace std;
string str;
int p;
int exp();
int term();
int factor();


int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    p=0;  
    cin>>str;
    cout<<exp()<<endl;
  }
  return 0;
}


int exp(){
  int val=term();
  while(str[p]=='+'||str[p]=='-'){
    if(str[p]=='+'){
      p++;
      val+=term();
    }
    else if(str[p]=='-'){
      p++;
      val-=term();
    }
  }
  return val;
}


int term(){
  
  int val=factor();
  while(str[p]=='*'||str[p]=='/'){
    if(str[p]=='*'){
      p++;
      val*=factor();
    }
    else if(str[p]=='/'){
      p++;
      val/=factor();
    }
  }
  return val;
}


int factor(){
  int val=0;
  
  if(str[p]=='('){
    p++;    
    val=exp();
    p++;
  }
  else{
    while('0'<=str[p]&&str[p]<='9'){
      val*=10;
      val+=(str[p]-'0');   
      p++;
    }
  }
  return val;
}