#include <cstdio>
#include <cassert>
#include <algorithm>
using namespace std;
 
char *pt;
int parseAtom();
int parseExpr();
int parseTerm();
int parseAtom() {
  if('0' <= *pt && *pt <= '9') {
    int x = *pt-'0';
    pt++;
    while('0' <= *pt && *pt <= '9') {
      x = x*10 + *pt-'0';
      pt++;
    }
    return x;
  }
  if('(' == *pt) {
    pt++;
    int x = parseExpr();
    assert(*pt == ')');
    pt++;
    return x;
  }
  assert(false);
  return -1;
}
int parseExpr() {
  int x = parseTerm();
  while(*pt == '+' || *pt == '-') {
    if(*pt == '+') {
      pt++;
      x += parseTerm();
    } else {
      pt++;
      x -= parseTerm();
    }
  }
  return x;
}
int parseTerm() {
  int x = parseAtom();
  while(*pt == '*' || *pt == '/') {
    if(*pt == '*') {
      pt++;
      x *= parseAtom();
    } else {
      pt++;
      x /= parseAtom();
    }
  }
  return x;
}
 
int main() {
  int tc; scanf("%d", &tc);
  for(int tci = 0; tci < tc; tci++) {
    static char expr[200]; scanf(" %s", expr);
    pt = expr;
    int x = parseExpr();
    assert(*pt == '=');
    printf("%d\n", x);
  }
  return 0;
}