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

string S;
size_t cur = 0;

bool isdigit(char a){
    if(a =='0' or a=='1' or a=='2' or a=='3' or a=='4' or a=='5' or a=='6' or a=='7' or a=='8' or a=='9'){
        return true;
    }
    else return false;
}

int digit(){
    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 factor();

int term(){
    int a = factor();
    while(cur < S.size() && (S[cur] == '*'|| S[cur] == '/')){
        char op = S[cur];
        cur +=1;
        int b = factor();
        if(op == '*') a *= b;
        else a /= b;
    }
    return a;
}

int expression(){
    int a = term();
    while(S[cur] == '+'|| S[cur] == '-'){
        char op = S[cur];
        cur += 1;
        int b = term();
        if (op == '+') a += b;
        else a -= b;
    }
    return a;
}

int factor(){
    if (S[cur] !='(') return number();
    cur += 1;
    int n = expression();
    assert(S[cur] == ')');
    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;
    }
    return 0;
}