#include <stdio.h>

char stk[50], psh[50];
int v[50],pri[256], sp, pp;

int calc(char *p) {
  int i;
  char *exp = p;
  for (i = 0; i < 256; pri[i++] = 3);   
  pri['+'] = pri['-'] = 1; pri['*'] = pri['/'] = 2; pri['('] = 4; pri[')'] = 0;
  stk[0] = 0; pri[0] = -1;
  sp = pp = 0;
  while (*p != '\0') {
    while (pri[*p] <= pri[stk[sp]] && stk[sp] != '(')psh[++pp] = stk[sp--];
    if (*p != ')')stk[++sp] = *p;
    else sp--;
    p++;
  }
  for (i = sp; i > 0; psh[++pp] = stk[i], i--);
  sp = 0;
  for (i = 1; i <= pp; i++) {
    if ('0' <= psh[i] && psh[i] <= '9')v[++sp] = psh[i] - '0';
    else {
      switch (psh[i]) {
      case '+':v[sp - 1] = v[sp - 1] + v[sp];break;
      case '-':v[sp - 1] = v[sp - 1] - v[sp];break;
      case '*':v[sp - 1] = v[sp - 1] * v[sp];break;
      case '/':v[sp - 1] = v[sp - 1] / v[sp];break;
      }
      sp--;
    }
  }
  printf("%d\n",v[1]);
}

int main() {
  int i, j, n;
  char p[50][100];
  scanf("%d", &n);
  for (i = 0; i < n; scanf("%s", p[i++]));
  for (i = 0; i < n; i++)
    for (j = 0; j < 100; j++)
      if (p[i][j] == '=')p[i][j] = '\0';
  for (i = 0; i < n; calc(p[i++]));
}