#include <iostream>
#include <string>
using namespace std;
int exp();
int term();
int factor();
int number();
int digit();
int p=0;
string str;
int main(){
  int n,re;
  cin >> n;
  while(n){
    cin >> str;
    re=exp();
    cout << re << endl;
    n--;
  }
  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();
  cout <<  val << endl;
  while(str[p]=='*'||str[p]=='/'){
    if(str[p]=='*'){
      p++;
      val*=factor();
    }else if(str[p]=='/'){
      p++;
      val/=factor();
    }
  }
  return val;
}
int factor(){
  int val=number();
  if(str[p]=='('){
    p++;
    val=exp();
  }else if(str[p]==')'){
    p++;
  }
  return val;
}
int number(){
  int val=digit();
  return val;
}
int digit(){
  cout << 'p' << p << endl;
  if(str[p]=='0'){
    p++;
    return 0;
  }
  else if(str[p]=='1'){
    p++;
    return 1;
  }
  else if(str[p]=='2'){
    p++;
    return 2;
  }
  else if(str[p]=='3'){
    p++;
    return 3;
  }
  else if(str[p]=='4'){
    p++;
    return 4;
  }
  else if(str[p]=='5'){
    p++;
    return 5;
  }
  else if(str[p]=='6'){
    p++;
    return 6;
  }
  else if(str[p]=='7'){
    p++;
    return 7;
  }
  else if(str[p]=='8'){
    p++;
    return 8;
  }
  else if(str[p]=='9'){
    p++;
    return 9;
  }
}