//Smart Calculator
#include <iostream>
#include <cstdio>
#include <cassert>
#define rep(i,n) for(int i = 0;i < n;i++)
#define mp make_pair
using namespace std;
string S;
size_t cur = 0;
bool isdigit(char);
int digit();
int number();
int term();
int expression();
int factor();
int parse(){
    return expression();
}

int main(){
    int n;
    cin >> n;
    rep(i,n){
        cur = 0;
        cin >> S;
        S.resize(S.size()-1);
        cout << parse() << endl;
    }
}

bool isdigit(char c){
    return c >= '0' && c <= '9';
}
int digit(){
    assert(isdigit(S[cur]));
    int n = S[cur] - '0';
    cur = cur + 1;
    return n;
}
int number(){
    int n = digit();
    while(cur<S.size()&&isdigit(S[cur])){
        n = n*10+digit();
    }
    return n;
}

int expression(){
    int mult = 1;
    if(S[cur]=='-'){
        mult = -1;
        cur++;
    }
    int sum = term()*mult;
    while(cur < S.size()&&(S[cur]=='+'||S[cur]=='-')){
        char op = S[cur];
        cur++;
        if(op == '+'){
            sum += term();
        }else{
            sum -= term();
        }
    }
    return sum;
}
int term(){
    int ret = factor();
    while(cur < S.size() &&( S[cur]=='*'||S[cur]=='/')){
        char op = S[cur];
        cur++;
        if(op == '*'){
            ret *= factor();
        }else{
            ret /= factor();
        }
    }
    return ret;
}
int factor(){
    if(S[cur]!='(')
        return number();
    cur += 1;
    int n = expression();
    assert(S[cur]==')');
    cur++;
    return n;
}