#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;

char s[125];
int it;

int dfs(){
  int ret = 0;
  int tail = 0;
  int sign = 1;
  // first operand
  int a = 0;
  if(s[it]=='('){
    it++;
    a = dfs();
    assert(s[it]==')');
    it++;
  }else{
    while(isdigit(s[it])){
      a *= 10;
      a += s[it]-'0';
      it++;
    }
  }
  tail = a;
  while(true){
    // operator
    char op = s[it];
    if(op == '=' || op == ')'){
      // end
      ret += sign * tail;
      return ret;
    }
    it++;
    // second operand
    int b = 0;
    if(s[it]=='('){
      it++;
      b = dfs();
      assert(s[it]==')');
      it++;
    }else{
      while(isdigit(s[it])){
        b *= 10;
        b += s[it]-'0';
        it++;
      }
    }
    if(op == '+' || op == '-'){
      // tail end
      ret += sign * tail;
      tail = b;
      sign = op=='+' ? 1 : -1;
    }else if(op == '*'){
      tail *= b;
    }else if(op == '/'){
      tail /= b;
    }
  }
}

void solve(){
  REP(i,125)s[i] = '\0';
  scanf("%s",s);
  it = 0;
  int ans = dfs();
  printf("%d\n",ans);
}

int main(){
  int t;
  scanf("%d",&t);
  while(t--)solve();
}
