#include <iostream>
#include <string>
using namespace std;

class calc{
  string s;
  string::iterator it;
public:
  calc(string str){
    s = str;
    it = str.begin();
  }

  int fact(){
    if(*it == '('){
      *it++;
      int ret = exp();
      *it++;
      return ret;
    } else {
      int ret = 0;
      while('0' <= *it && *it <= '9'){
	ret *= 10;
	ret += *it-'0';
	++it;
      }
      return ret; 
    }
}

  int turm(){
    int ret = fact();
    while(*it == '*' || *it == '/'){
      if(*it == '*'){
	*it++;
	ret *= fact();
 
      } else if(*it == '/'){
	*it++;
	ret /= fact(); 
      }
    }
    return ret;
  }
  int exp(){
    int ret = turm();
    while(*it == '+' || *it == '-'){
      if(*it == '+'){
	*it++;
	ret += turm();
 
      } else if(*it == '-'){
	*it++;
	ret -= turm(); 
      }
    }
    return ret;
  }
};

int main(){
  int n;
  cin >> n;
  while(n--){
    string str;
    cin >> str;
    calc ans(str);
    cout << ans.exp() << endl;
  }
  return 0;
}