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

int exp();
int term();
int factor();
string str;
int p;

int factor(){
  int val=0;
  while(str[p]>='0' && str[p]<='9'){ 
    val*=10;
    val+=str[p]-'0';
    p++;
  }
  
  if(str[p]=='('){
    p++;
    val=exp();
  }
  if(str[p]==')') p++;
  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 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 main(){
  int n;
  
  cin>>n;
  for(int i=0;i<n;i++){
    p=0;
    cin>>str;
    cout<<exp()<<endl;
  }
  return 0;
}