#include <iostream>
#include <string>
#include <cmath>
using namespace std;

#define rep(i,n) for (int i = 0; i < int(n); i++)
//typedef long long ll;
typedef int ll;

int it, n;
string input;

ll expr();
ll term();
ll fact();

ll expr() {
    int v = term();
    while (input[it] == '+' || input[it] == '-') {
        if (input[it++] == '+') {
            v += term();
        } else {
            v -= term();
        }
    }
    return v;
}

ll term() {
    int v = fact();
    while (input[it] == '*' || input[it] == '/') {
        if (input[it++] == '*') {
            v *= term();
        } else {
            v = (int)trunc(1.0*v/term());
            //v /= term();
        }
    }
    return v;
}

ll fact() {
    int v = 0;
    if (input[it] == '(') {
        ++it; // '('
        v = expr();
        ++it; // ')'
    } else {
        int sign = input[it] == '-' ? ++it, -1 : 1;
        while ('0' <= input[it] && input[it] <= '9') {
            v = 10*v + input[it]-'0';
            ++it;
        }
        v *= sign;
    }
    return v;
}

int main() {
    cin >> n;
    rep (i,n) {
        cin >> input;
        it = 0;
        cout << expr() << endl;
    }
}