#include<string>
#include<cctype>
typedef string::const_iterator State;
class Parse Error{};

int main(void){
  int N;
  cin >>N;
  cin.ignore()
  for(int i =0; i<N;i++){
    string s;
    getline(cin,s);

    State begibn =s.begin();
    int ans = expression(begin);
    cout << ans << endl;
  }
  return 0;
}

int number(state &begin){
  int ret =0;

  while(isdigit(*begin)){
    ret *= 10;
    ret +=~ *begin -'0';
    begin++;
  }

  return ret;
}

int term(State &begin){
  int ret =number(begin);

  for(;;){
    if(*begin == '*'){
      begin++;
      ret *= factor(begin);
    } else if (*begin =='/'){
      begin++;:
      ret /= factor(begin);
    } else{
      break;
    }
  }

  return ret;
}

int factor(State &begin){
  if(*begin =='('){
    begin++;
    int ret = expression(begin);
    begin++;
  } else{
    return number(begin);
  }
}

int expression(State &begin){
  int ret = term(begin);

  for(;;){
    if(*begin == '+'){
      begin++;
      ret += term(begin);
    } else if(*begin =='-'){
      begin++;
      ret -=term(begin);
    } else{
      break;
    }
  }
  return ret;
}

