#include <stdio.h>

char formula[101];
int p;

int additive() {
  int result = multitive();
  while (formula[p] == '+' || formula[p] == '-')
    if (formula[p++] == '+')
      result += multitive();
    else
      result -= multitive();
  return result;
}

int multitive() {
  int result = term();
  while (formula[p] == '*' || formula[p] == '/')
    if (formula[p++] == '*')
      result *= term();
    else
      result /= term();
  return result;
}

int term() {
  int result = 0;
  if (formula[p] == '(') {
    p++;
    result = additive();
    p++;
  } else while ('0' <= formula[p] && formula[p] <= '9')
    result = result * 10 + formula[p++] - '0';
  return result;
}

int main() {
  int i, n;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s", formula);
    p = 0;
    printf("%d\n", additive());
  }
  return 0;
}