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

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)

string S = "3*(12+3)";
size_t cur = 0;

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 += 1;
  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 a/= b;
  }
  return a;
}

int expression() {
  int a = term();
  while (cur < S.size() && (S[cur] == '+' || S[cur] == '-')) {
    char op = S[cur++];
    int b = term();
    if (op == '+') a += b; else a -= b;
  }
  return a;
}

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

int main (int argc, char const* argv[]) {
  int n; cin>>n;
  rep(i,n) {
    cin>>S;
    S.erase(S.size()-1);
    //cout<<S<<endl;
    cout<<parse()<<endl;
  }
  return 0;
}