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

string S;
size_t cur = 0;
int expression();
int digit();
int number();
int parse();
int term();
int factor();

int main(){
  int n;
  cin >> n;
  for (int i=0; i<n; i++){
    cin >> S;
    int a = parse();
    //  assert (a == 15);
    assert (cur == S.size()-1);
    cout << a << endl;
    cur = 0;
  }
}

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()-1 && 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();
    assert(op == '+' || op == '-');
    if (op == '+')  sum += b;
    else sum -= b;
  }
  return sum;
}

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

int parse(){
  return expression();
}