 #include<iostream>
 #include<string>
 
 using namespace std;
 
 int expression();
 int term();
 int factor();
 
 string exp;
 int p;
 
 int expression(){
     int value = term();
     if( exp[p] == '+' || exp[p] == '-' ){
         if ( exp[p] == '+' ) { p++; value += term(); }
         else { p++; value -= term(); }
     }
     return value;
 }
 
 int term(){
     int value = factor();
     if( exp[p] == '*' || exp[p] == '/' ){
         if ( exp[p] == '*' ) { p++; value *= factor(); }
         else { p++; value /= factor(); }
     }
     return value;
 }
 
 int factor(){
     int value = 0;
     if ( exp[p] == '(' ){
         p++; value = expression(); p++;
     } else {
         while( isdigit(exp[p]) ) { value = value*10 + exp[p++] - '0';}
     }
     return value;
 }
 
 int main(){
     int tcase; cin >> tcase;
     for ( int i = 0; i < tcase; i++ ){
         cin >> exp;
         p = 0;
         cout << expression() << endl;
     }
     return 0;
 }