#include <iostream>

using namespace std;

int exp(char a[]);
int term(char a[]);
int factor(char a[]);
int p;

int exp(char a[])
{
  int x = term(a);
  while(a[p] == '+' || a[p] == '-'){
    if(a[p] == '+'){
      p++;
      x += term(a);
    } else {
      p++;
      x -= term(a);
    }
  }

  return x;
}

int term(char a[])
{
  int x = factor(a);
  while(a[p] == '*' || a[p] == '/'){
    if(a[p] == '*'){
      p++;
      x *= factor(a);
    } else {
      p++;
      x /= factor(a);
    }
  }

  return x;
}

int factor(char a[])
{
  int x;
  if(a[p] == '('){
    p++;
    x = exp(a);
    if(a[p] == ')'){
      p++;
    }
  } else {
    x = (int)(a[p]-'0');
    p++;
  }

  return x;
}

int main()
{
  int n;
  char a[101];

  while(cin>>n && n){
    while(n--){
      scanf("%s", a);
      p = 0;
      cout << exp(a) << endl;
    }
  }

  return 0;
}