#include <iostream>
#include <cassert>
#include <cctype>
using namespace std;
string S;
size_t cur;
int expression();

int digit() {
    //  Digit := '0' | '1' | ... | '9'
    assert(isdigit(S[cur]));    // S[cur] が数字であることを確認
    int n = S[cur] - '0';       // '0' を 0 に変換
    cur = cur + 1;              // 一文字進める
    return n;
}

int number() {
    //  Number := Digit の繰り返し
    int n = digit();
    while (cur < S.size() && isdigit(S[cur])) {     // 次も数字が 1 文字先読み
        n = n * 10 + digit();
    }
    return n;
}

int factor() {
    //  Factor := '(' Expression ')' | Number
    if (S[cur] != '(') return number();
    cur += 1;
    int n = expression();
    assert(S[cur] == ')');
    cur += 1;
    return n;
}

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

int expression() {
    //  Expression := Term { ('+'|'-') Term }
    int a = term();
    while (cur < S.size() && (S[cur] == '+' || S[cur] == '-')) {
        char op = S[cur++];
        int b = term();
        if (op == '+') a += b; else a -= b;
    }
    return a;
}

int parse() { return expression(); }

int main() {
    int n; cin >> n;
    while (n--) {
        cin >> S;
        cur = 0;
        S.resize(S.size() - 1);     // 最後の = を無視
        cout << expression() << endl;
    }
    return 0;
}
