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

int num(string&, int&);
int term(string&, int&);
int mul(string&, int&);
int expr(string&, int&);

int num(string &s, int &k) {
    int ret = 0;
    while ('0' <= s[k] && s[k] <= '9') {
        ret *= 10;
        ret += s[k] - '0';
        k ++;
    }
    return ret;
}

int term(string &s, int &k) {
    int sym = 1;
    if (s[k] == '+') {
        sym = 1;
        k ++;
    } else if (s[k] == '-') {
        sym = -1;
        k ++;
    }
    int ret;
    if (s[k] == '(') {
        k ++;
        ret = expr(s, k);
        k ++;
    } else {
        ret = num(s, k);
    }
    return sym * ret;
}

int mul(string &s, int &k) {
    int ret = term(s, k);
    if (s[k] == '*') {
        k ++;
        return ret * mul(s, k);
    } else if (s[k] == '/') {
        k ++;
        return ret / mul(s, k);
    }
    return ret;
}

int expr(string &s, int &k) {
    int ret = mul(s, k);
    if (s[k] == '+') {
        k ++;
        return ret + expr(s, k);
    } else if (s[k] == '-') {
        k ++;
        return ret - expr(s, k);
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    string s;
    while (n--) {
        cin >> s;
        int pos = 0;
        cout << expr(s, pos) << endl;
    }
    return 0;
}