#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define fst first
string s;
int id;

bool left(){
  return id < (int)s.size()-1;
}
char peek(){
  return s[id];
}
char pop(){
  return s[id++];
}
void eat(char c){
  assert(s[id] == c);
  id++;
}
int expr();
int number(){
  int res = 0;
  while (left() && isdigit(peek())) {
    res = res * 10 + pop() - '0';
  }
  return res;
}
int fact(){
  int res;
  if (isdigit(peek())) {
    return res = number();
  } else {
    eat('(');
    res = expr();
    eat(')');
    return res;
  }
}
int term(){
  int res = fact();
  while (left() && (peek() == '*' || peek() == '/')) {
    if (peek() == '*') {
      eat('*');
      res *= fact();
    } else {
      eat('/');
      res /= fact();
    }
  }
  return res;
}
int expr(){
  int res = term();
  while (left() && (peek() == '+' || peek() == '-')) {
    if (peek() == '+') {
      eat('+');
      res += term();
    } else {
      eat('-');
      res -= term();
    }
  }
  return res;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  REP(i,n){
    id = 0;
    cin >> s;
    cout << expr() << endl;
  }
  return 0;
}
