#include<iostream>
#include<sstream>

using namespace std;

string str;

bool isNum(string s){
  for(int i = 1; i < s.length(); i++)
    if(s[i] < '0' || s[i] > '9') return false;

  return true;
}

int solve(string s){

  // cout << s << endl;
  if(isNum(s)){
    if(s[0] != '-'){
      stringstream ss(s);
      int out;
      ss >> out;
      return out;

    }else{
      string s1 = "";

      for(int i = 1; i < s.length(); i++)
	s1+=s[i];
      stringstream ss(s1);
      int out;
      ss >> out;
      return -1*out;
    }
  }

  int pos = -1;


  for(int i = 0; i < s.length(); i++)
    if((i&&(s[i] == '+' || s[i] == '-')) ||  s[i] == '('){
      pos = i;
      break;
    }

  if(pos == -1){
    int now = 0;
    string a,b;
    a = b = "";

    for(int i = 0; i < s.length(); i++){
      if(s[i] == '*' || s[i] == '/'){
	now = i;
	break;
      }
      a += s[i];

    }

    for(int i = now+1; i < s.length(); i++)
      b+=s[i];

    if(s[now] == '+') return solve(a)+solve(b);
    if(s[now] == '-') return solve(a)-solve(b);
    if(s[now] == '*') return solve(a)*solve(b);
    if(s[now] == '/') return solve(a)/solve(b);

  }else{

    string a,b;
    a = b = "";

    for(int i = 0; i < pos; i++)
      a += s[i];
    for(int i = pos+1; i < s.length(); i++)
      b += s[i];

    if(s[pos] == '+') return solve(a)+solve(b);
    else if(s[pos] == '-') return solve(a)-solve(b);
    else if(s[pos] == '('){

      if(pos == 0){

	int par = 1;
	a = b = "";
	int now;

	for(int i = 1; i < s.length(); i++){
	  if(s[i] == '(') par++;
	  if(s[i] == ')') par--;
	  a+=s[i];
	  if(par == 0){
	    now = i+1;
	    break;
	  }
	}

	if(now == s.length()){
	  for(int i = 1; i < s.length()-1; i++)
	    b += s[i];

	  return solve(b);
	}

	for(int i = now+1; i < s.length(); i++)
	  b+=s[i];

	if(s[now] == '+') return solve(a)+solve(b);
	if(s[now] == '-') return solve(a)-solve(b);
	if(s[now] == '*') return solve(a)*solve(b);
	if(s[now] == '/') return solve(a)/solve(b);
	


      }else{
	a = b = "";

	for(int i = 0; i < pos-1; i++)
	  a+=s[i];

	for(int i = pos; i < s.length(); i++)
	  b+=s[i];

	if(s[pos-1] == '+') return solve(a)+solve(b);
	if(s[pos-1] == '-') return solve(a)-solve(b);
	if(s[pos-1] == '*') return solve(a)*solve(b);
	if(s[pos-1] == '/') return solve(a)/solve(b);
       
      }
    }
  }

}

string make(string s){
  string out = "";

  for(int i = 0; i < s.length()-1; i++)
    out += s[i];

  return out;
}

int main(){
  int n;
  cin >> n;
  while(n--){
    cin >> str;
    str = make(str);
    cout << solve(str) << endl;
  }
  return 0;
}