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

#define CK(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
#define ll long long;

const int INF = 1e9;
const long long  LLINF = 1e15;

using namespace std;

typedef string::const_iterator State;

int number(State &);
int factor(State &);
int term(State &);
int expression(State &);

// ??°??????????????????????????????????????°????????????
int number(State &begin) {
  int ret = 0;
  while (isdigit(*begin)) {
    ret *= 10;
    ret += *begin - '0';
    begin++;
  }
  return ret;
}

// ??¬??§?????°???????????????????????????????????????????????????
int factor(State &begin) {
    if (*begin == '(') {
        begin++; // '('????£???°??????
        int ret = expression(begin);
        begin++; // ')'????£???°??????
        return ret;
    } else {
        return number(begin);
    }
    //??¨????????????
    return -INF;
}

// ?????????????????????????????????????????????????????????????????????
int term(State &begin) {
  int ret = factor(begin);
  for (;;) {
    if (*begin == '*') {
        begin++;
        ret *= factor(begin);
    } else if (*begin == '/') {
        begin++;
        ret /= factor(begin);
    } else {
        break;
    }
  }
  return ret;
}

// ?????????????????????????????????????????????????????????????????????
int expression(State &begin) {
  int ret = term(begin);
  for (;;) {
    if (*begin == '+') {
        begin++;
        ret += term(begin);
    } else if (*begin == '-') {
        begin++;
        ret -= term(begin);
    } else {
        break;
    }
  }
  return ret;
}


int main() {
  int N;
  cin>>N;
  REP(i,0,N){
    string S;
    cin>>S;
    State state = S.begin();
    cout<<expression(state)<<endl;
  }
  return 0;
}