#include <iostream>
#include <cassert>
#define REP(i,l,n) for(int i=l;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define MAX 100
using namespace std;
int ans;
int n,pointer;
char input[MAX];
int evalE();
int evalT();
int evalF();
int main(){
  cin >> n;
  rep(i,n){
    pointer = 0;
    cin >> input;
    ans = evalE();
    cout << ans <<endl;
  }
  return 0;
}
int evalE(){
  int value = evalT();
  while(true){
    if(input[pointer] == '+'){
      pointer++;
      value += evalT();
    }else if(input[pointer] == '-'){
      pointer++;
      value -= evalT();
    }else{
      break;
    }
  }
  return value;
}
int evalT(){
  int value = evalF();
  while(true){
    if(input[pointer] == '*'){
      pointer++;
      value *= evalF();
    }else if(input[pointer] == '/'){
      pointer++;
      value /= evalF();
    }else{
      break;
    }
  }
  return value;
}
int evalF(){
  int value = 0;
  if(input[pointer] == '('){
    pointer++;
    value = evalE();
    assert(input[pointer] == ')');
    pointer++;
  }
  while(input[pointer]>='0'&&input[pointer]<='9'){
    value *= 10;
    value += (int)(input[pointer++] - '0');
  }
  return value;
}