#include <iostream>
#include <string>
#include <cctype>
#include <cassert>
#include <algorithm>
using namespace std;
size_t cur;
string s;

int expression();

int digit(){
  assert(cur < s.size());
  return s[cur++] - '0';
}
int number(){
  int n = 0.0;
  assert(cur < s.size());
  while(cur < s.size() && isdigit(s[cur])){
    n = n * 10 + digit();
  }
  return n;
}

int factor(){
  assert(cur < s.size());
  if(isdigit(s[cur])){
    return number();
  }else{
    cur++;
    int a = expression();
    assert(s[cur] == ')');
    cur++;
    return a;
  }
}

int term(){
  assert(cur < s.size());
  int a = factor();
    while(cur < s.size() && (s[cur] == '*' || s[cur] == '/')){
    char op = s[cur++];
    int b = factor();
    if(op == '*') a *= b; else a /= b;
  }
  return a;
}

int expression(){
  assert(cur < s.size());
  int a = term();
  while(cur < s.size() && (s[cur] == '-' || s[cur] == '+')){
    char op = s[cur++];
    int b = term();
    if(op == '-') a -= b; else a += b;
  }
  return a;
}

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    cur = 0;
    cin >> s;
    cout << expression() << endl;
  }
  return 0;
}