#include <iostream>
#include <cassert>
#include <string>
#include <cctype>

using namespace std;
int cur = 0;
string S;
int expression();
int term();
int factor();
int main() {
  int times;
  cin >>times;
  for(int i = 0 ; i < times; i++){
      cin >> S;
      cur = 0;
      S.resize(S.size()-1);
      cout << expression() <<endl;
  }

}
int digit() {
  assert(isdigit(S[cur]));
  int n = S[cur] -'0';
  cur = cur+1;
  return n;
}
int number() {
  int n = digit();
  while(cur <S.size() && isdigit(S[cur])){
      n = n*10 + digit();
  }
  return n;
}
int expression() {
  int sum = term();
  while (S[cur] == '+' || S[cur] == '-'){
    char op = S[cur];
    cur +=1;
    int b = term();
    if(op ==  '+') sum +=b;
    else sum -= b;
  }
  return sum;
}
int term() {
  int a = factor();
  while(cur < S.size()
        && (S[cur] == '*' || S[cur] == '/')){
          char op = S[cur];
          cur +=1;
          int b = factor();
          if(op == '*') a *=b;
          else a/=b;
        }
  return a;
}
int factor() {
  if(S[cur] != '(' ) return number();
  cur +=1;
  int n =expression();
  assert(S[cur] == ')');
  cur +=1;
  return n;
}