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

using namespace std;

string S;
size_t cur = 0;

int digit(){
  assert(isdigit(S[cur]));
  int n = S[cur] - '0';
  cur += 1;
  return n;
}

int number(){
  int n = digit();
  while(cur<S.size()&&isdigit(S[cur])){
    n = n*10 + digit();
  }
  return n;
}

int factor();

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 expression(){
  int a = term();
  while(cur<S.size()&&(S[cur] == '+' || S[cur] == '-')){
    char op = S[cur];
    cur += 1;
    int b = term();
    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;
}

int parse(){
  cur = 0;
  return expression();
}

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;++i){
    cin >> S;
    S.pop_back();

    int a = parse();

    cout << a << endl;
  }
}