#include <iostream>
#include <cassert>
#include <cctype>
using namespace std;

string S;
size_t cur;

int parse();
int expression();

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

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

int factor(){
  if(S[cur] != '(') return number();
  cur++;
  int n = expression();
  assert(S[cur] == ')');
  cur++;
  return n;
}

int term(){
  int a = factor();
  while(cur < S.size() && (S[cur] == '*' || S[cur] == '/')){
    char op = S[cur++];
    int b = factor();
    if(op == '*') a *= b;
    else {
      assert(b != 0);
      a /= b;
    };
  }
  return a;
}


int expression(){
  int sum = term();
  while(S[cur] == '+' || S[cur] == '-'){
    char op = S[cur];
    cur++;
    int b = term();
    if (op == '+') sum += b;
    else sum -= b;
  }
  return sum;
}
int parse() { return expression(); }

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> S;
    S.resize(S.size()-1);
    cur = 0;
    cout << expression() << endl;
  }
}