#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
LL plusub(void);
LL muldiv(void);
LL parent(void);
LL number(void);

int ind;
string str;

LL plusub(void){
  LL a=muldiv();
  if(str[ind]=='+'){
    ++ind;
    return a+plusub();
  }else if(str[ind]=='-'){
    ++ind;
    return a-plusub();
  }else return a;
}

LL muldiv(void){
  LL a=parent();
  if(str[ind]=='*'){
    ++ind;
    return a*muldiv();
  }else if(str[ind]=='/'){
    ++ind;
    return a/muldiv();
  }else return a;
}

LL parent(void){
  if(str[ind]=='('){
    ++ind;
    LL a=plusub();
    ++ind;
    return a;
  }else return number();
}

LL number(void){
  if('0'<=str[ind] && str[ind]<='9'){
    LL a=str[ind]-'0';
    ++ind;
    LL b=number();
    if(0<=b) return a*10+b;
    else return a;
  }else return -1;
}

int main(void)
{
  int n;
  cin >> n;
  REP(i,n){
    ind=0;
    cin >> str;
    cout << plusub() << endl;
  }
  return 0;
}