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

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)

bool is_digit(char c){
  return '0' <= c && c <= '9';
}
string i2s(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}

string parse(int i, string s) {
  //cout<<s<<endl;
  bool flag = true;
  
  // brace
  if (s.find('(') != -1) {
    // æª©ç`FbNµÄA')'Éoï¤êÆ
    // »¤ÅÈ¢êÉª¯é
    bool mode = true;
    REP(j,s.find('(')+1, s.size()) {
      if (s[j] == ')') break;
      if (s[j] == '(') {
        mode = false;
        break;
      }
    }
    // ÊÌÊuðæ¾·é
    int lbr = s.find('('), rbr;
    if (mode) {
      rbr = s.find(')');
    } else {
      for(int j=s.size()-1;j>=0;j--) if (s[j] == ')') {
        rbr = j; break;
      }
    }
    // ÊàÌvZðæÉs¤½ßÉssð¾é
    string inner = parse(0, s.substr(lbr+1, rbr-lbr-1));
    // ÊàðÁ·é
    s.erase(lbr, rbr-lbr+1);
    s.insert(lbr, inner);
    //cout<<"brace:"<<s<<endl;
    return parse(0, s);
  }
  
  rep(i,s.size()) if (s[i] == '*' || s[i] == '/') {
    int lhs, rhs, res;
    int li = i-1, ri = i+1;
    if (ri + 1 < s.size() && s[ri] == '-') ri++;

    while (is_digit(s[li]) || s[li] == '-' && li >= 0) li--;
    while (is_digit(s[ri]) && ri < s.size()) ri++;
    lhs = atoi(s.substr(li+1, i-1-li).c_str());
    rhs = atoi(s.substr(i+1, ri-1-i).c_str());
    //cout<<s.substr(li+1, i-1-li)<<"|"<<s.substr(i+1, ri-1-i)<<endl;

    if (lhs == 0 || rhs == 0) {
      res = 0;
    } else {
      if (s[i] == '*') {
        res = lhs * rhs;
      } else {
        res = lhs / rhs;
      }
    }
    
    s.erase(li+1, ri-li-1);
    s.insert(li+1, i2s(res));
    return parse(0, s);
  }
  
  rep(i,s.size()) if (s[i] == '+' || s[i] == '-') {
    if (s[i] == '-' && i == 0) continue; 
    int lhs, rhs, res;
    int li = i-1, ri = i+1;
    if (ri + 1 < s.size() && s[ri] == '-') ri++;
    
    while (is_digit(s[li]) || s[li] == '-' && li >= 0) li--;
    while (is_digit(s[ri]) && ri < s.size()) ri++;
    lhs = atoi(s.substr(li+1, i-1-li).c_str());
    rhs = atoi(s.substr(i+1, ri-1-i).c_str());
    //cout<<"dbg::"<<li<<"|"<<ri<<endl;
    //cout<<s.substr(li+1, i-1-li)<<"|"<<s.substr(i+1, ri-1-i)<<endl;
    if (s[i] == '+') {
      res = lhs + rhs;
    } else {
      res = lhs - rhs;
    }
    s.erase(li+1, ri-li-1);
    s.insert(li+1, i2s(res));
    //cout<<s<<endl;
    return parse(0, s);
  }
  
  return s;
}

void solve() {
  string s; cin>>s;
  s = s.substr(0, s.size()-1);
  cout<<parse(0, s)<<endl;
}

int main (int argc, char const* argv[]) {
  int n; cin>>n;
  rep(i,n) solve();
  return 0;
}