#include<iostream>
#include<cctype>
#include<cassert>
using namespace std;

string s;
int cur;

int factor();

char readchar(){
  assert(cur <s.size());
  char ret =s[cur];
  cur += 1;
  return ret;
}

char peak(){
  assert(cur<s.size());
  return s[cur];
}

int digit(){
  assert(isdigit(peak()));
  int n = readchar() - '0';
  return n;
}

int number(){
  int n= digit();
  while(cur<s.size()&&isdigit(peak()))
    n=n*10+digit();
  return n;
}

int term(){
  int a = factor();
  while((cur <s.size()) && (peak()=='*' || peak() == '/')){
    char op = readchar();
    int b = factor();
    if(op=='*') a*=b; else a/=b;
  }

  return a;
}
    
int expression(){
  int a=term();
  while((cur<s.size())&& (peak()=='+' || peak() == '-')){
    char op = readchar();
    int b= term();
    if(op == '+') a+=b;else a-=b;
  }
  return a;
}

int factor(){
  if(peak() != '(') return number();
  cur += 1;
  int n = expression();
  assert(peak() == ')');
  cur+=1;
  return n;
}


int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cur=0;
    cin>>s;
    s.resize(s.size()-1);
    cout<<expression() <<endl;
  }
}