#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int calc(char *s, int &i, bool f = false){
  int ret = 0;
  bool flag = i >= 0 && s[i-1] == '(';
  
  for(;s[i];){
    
    if(s[i] == ')'){
      if(flag) i++;
      return ret;
    }
    
    if(s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/'){

      i++;
      
      if(s[i] == '('){
        i++;

        if(i-2 < 0) ret += calc(s,i);
        else if(s[i-2] == '+') ret += calc(s,i,false);
        else if(s[i-2] == '-') ret -= calc(s,i,false);
        else if(s[i-2] == '*') ret *= calc(s,i,false);
        else if(s[i-2] == '/') ret /= calc(s,i,false);

        continue;
      }
      
      if(s[i-1] == '+') ret += calc(s,i,true);
      else if(s[i-1] == '-') ret -= calc(s,i,true);
      
    }else{
      int start = i-1;
      int sum = 0;
      
      while(!(s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/' || s[i] == '\0' || s[i] == ')')){
        sum *= 10;
        sum += s[i] - '0';
        i++;
      }
      /*
      debug(ret);
      debug(sum);
      debug(s[start]);
      */
      
      if(start < 0){
        ret += sum;
      }else{
        if(s[start] == '(') ret += sum;
        if(s[start] == '+') ret += sum;
        if(s[start] == '-') ret += sum;
        if(s[start] == '*') ret *= sum;
        if(s[start] == '/') ret /= sum;
      }
      
      if(f && (s[i] == '+' || s[i] == '-')){
        //debug(i);
        //debug(s[i]);
        return ret;
      }
      
      //debug(ret);
    }
  }

  //debug(s[i]);
  //debug(ret);
  
  return ret;
}


int main(){
  char s[SIZE];
  int t = 0;

  int n;

  scanf("%d",&n);

  while(n--){
    char s2[SIZE] = {};
    t = 0;
    scanf("%s",s);

    s[strlen(s)-1] = '\0';
    strcat(s2,"0+");
    strcat(s2,s);

    string str = s2;
    int r = 0;

    while((r = (int)str.find("((")) != -1){
      str.replace(r, 2, "(0+(");
    }

    sprintf(s2,"%s",str.c_str());
    
    printf("%d\n",calc(s2,t));
  }
  
  return 0;
}