#include<iostream>
#include<cctype> // isdigit
#include<cassert> // assert
using namespace std;

struct Result{int value,pos;};

int calculate(string expression);
Result equation(string expression,int pos);
Result factor(string expression,int pos);
Result term(string expression,int pos);

int calculate(string expression)
{
  return equation(expression,0).value;
}

Result equation(string expression,int pos)
{
  Result r=factor(expression,pos);
  // Á¸Z
  while(expression[r.pos]=='+' || expression[r.pos]=='-'){
    Result _r=factor(expression,r.pos+1);
    if(expression[r.pos]=='+')r.value += _r.value;
    if(expression[r.pos]=='-')r.value -= _r.value;
    r.pos=_r.pos;
  }
  return r;
}
Result factor(string expression,int pos)
{
  Result r=term(expression,pos);
  // æZ
  while(expression[r.pos]=='*' || expression[r.pos]=='/'){
    Result _r=term(expression,r.pos+1);
    if(expression[r.pos]=='*')r.value *= _r.value;
    if(expression[r.pos]=='/')r.value /= _r.value;
    r.pos=_r.pos;
  }
  return r;
}
Result term(string expression,int pos)
{
  Result r;
  // l
  if(isdigit(expression[pos])){
    int value=0;
    while(isdigit(expression[pos]))value += value*10 + expression[pos++]-'0';
    r.value=value;
    r.pos=pos;
    return r;
  }
  // PZqÌ}CiX
  if(expression[pos]=='-'){
    r=equation(expression,pos+1);
    r.value*=-1;
    return r;
  }
  // Ê
  if(expression[pos]=='('){
    r=equation(expression,pos+1);
    assert(expression[r.pos++]==')');
    return r;
  }
}

int main()
{
  int n;
  string s;
  cin>>n;
  while(n-->0){
    cin>>s;
    s=s.substr(0,s.size()-1);
    cout<<calculate(s)<<endl;
  }
}