#include <stdio.h>

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

int calc(char *p) {
  int i;
  char *exp = p;
  for (i = 0; i < 256; i++)
    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; i--)
    psh[++pp] = stk[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",(int)v[1]);
}
int main() {
  int i, j, n;
  char p[50][100];
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    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; i++)
    calc(p[i]);
}