#include <cstdio>
#include <cctype>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>

int apply(int lhs, char op, int rhs) {
  switch (op) {
  case '+': return lhs+rhs;
  case '-': return lhs-rhs;
  case '*': return lhs*rhs;
  case '/': return lhs/rhs;
  }
  assert(false);
}

int parse(const std::string &s, size_t &i, size_t preced=0) {
  const std::vector<std::string> ops={"+-", "*/"};
  if (preced == ops.size()) {
    if (s[i] == '(') {
      int res=parse(s, ++i, 0);
      assert(s[i] == ')');
      ++i;
      return res;
    }
    if (isdigit(s[i])) {
      int res=s[i]-'0';
      while (++i < s.length() && isdigit(s[i]))
        res = res*10+s[i]-'0';
      return res;
    }
    assert(false);
  }
  int res=parse(s, i, preced+1);
  while (i < s.length()) {
    char op=s[i];
    if (!std::count(ops[preced].begin(), ops[preced].end(), op)) break;
    int tmp=parse(s, ++i, preced+1);
    res = apply(res, op, tmp);
  }
  return res;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i=0; i<n; ++i) {
    char buf[128];
    scanf("%s", buf);
    std::string s=buf;
    size_t j=0;
    printf("%d\n", parse(s, j));
  }
}

