#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <utility>
using namespace std;

typedef pair<int, int> Pair;

int _;
int n;
char buf[11451419];

Pair EvalElem(int pos);
Pair EvalTerm(int pos);
Pair EvalExp(int pos);

Pair EvalElem(int pos) {
  if (buf[pos] == '(') {
    Pair p = EvalExp(pos+1);
    return Pair(p.first, p.second+1);
  }

  char c = buf[pos];

  if ('0' <= c && c <= '9') {
    char *next;
    int res = strtol(buf+pos, &next, 10);
    return Pair(res, next-buf);
  }

  return Pair(-1, -1);
}

Pair EvalTerm(int pos) {
  Pair p = EvalElem(pos);
  assert(p.second != -1);

  pos = p.second;
  if (buf[pos] == '*') {
    Pair q = EvalTerm(pos+1);
    return Pair(p.first*q.first, q.second);
  }

  if (buf[pos] == '/') {
    Pair q = EvalTerm(pos+1);
    return Pair(p.first/q.first, q.second);
  }

  return p;
}

Pair EvalExp(int pos) {
  Pair p = EvalTerm(pos);
  pos = p.second;
  int res = p.first;
  if (buf[pos] == '=' || buf[pos] == ')') {
    return Pair(res, pos);
  }

  Pair q = EvalExp(pos+1);
  if (buf[pos] == '+') res += q.first;
  else if (buf[pos] == '-') res -= q.first;
  else assert(0);

  return Pair(res, q.second);
}

int main() {
  scanf("%d", &_);
  while (_--) {
    scanf("%s", buf);
    n = strlen(buf);

    Pair res = EvalExp(0);
    assert(res.second == n-1);
    printf("%d\n", res.first);
  }
}