#include <iostream>
#include <cstdio>
#include <string>
#include <cctype>

using namespace std;

typedef string::const_iterator State;
class ParseError {};

int expression(State&);
int number(State&);
int factor(State&);
int term(State&);

int expression(State &begin){
  //cout <<"expression"<<endl;
  int ret = term(begin);
  while(1){
    if(*begin == '+'){
      begin++;
      ret += term(begin);
    }
    else if(*begin == '-'){
      begin++;
      ret -= term(begin);
    }
    else break;
  }
  return ret;
}

int term(State &begin){
  //cout <<"term"<<endl;
  int ret = factor(begin);
  
  while(1){
    if(*begin == '*'){
      begin++;
      ret *= factor(begin);
    }
    else if(*begin == '/'){
      begin++;
      ret /= factor(begin);
    }
    else break;
  }
  return ret;
}

int number(State &begin){
  //cout <<"number"<<endl;
  int ret = 0;
  while(isdigit(*begin)){
    ret *= 10;
    ret += *begin - '0';
    begin++;
  }
  return ret;
}

int factor(State &begin){
  //cout <<"factor"<<endl;
  if(*begin == '('){
    begin++;
    int ret = expression(begin);
    begin++; // ')' をスキップ
    return ret;
  }

  if(*begin == '-'){
    begin++;
    return -factor(begin);
  }
  return number(begin);
}

// beginがexpectedを指していたらbeginを一つ進める。
/*void consume(State &begin, char expected) {
  if (*begin == expected) {
    begin++;
  } else {
    cerr << "Expected '" << expected << "' but got '" << *begin << "'"
	 << endl;
    cerr << "Rest string is '";
    while (*begin) {
      cerr << *begin++;
    }
    cerr << "'" << endl;
    throw ParseError();
    }
    }*/

int main(){
  int n;
  cin >> n;
  cin.ignore();
  for(int i = 0 ; i < n ; i++){
    string s;
    getline(cin, s);
    //cout << s << endl;
    State begin = s.begin();
    int ans = expression(begin);
    //consume(begin, '=');
    cout << ans << endl;
  }
  return 0;
}