#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int expr(string& s, int& i);
int term(string& s, int& i);
int factor(string& s, int& i);
int number(string& s, int& i);

int expr(string& s, int& i) {
    int val = term(s, i);
    while (s[i] == '+' || s[i] == '-') {
        char op = s[i];
        ++i;
        int val2 = term(s, i);
        if (op == '+') val += val2;
        else val -= val2;
    }
    return val;
}

int term(string& s, int& i) {
    int val = factor(s, i);
    while (s[i] == '*' || s[i] == '/') {
        char op = s[i];
        ++i;
        int val2 = factor(s, i);
        if (op == '*') val *= val2;
        else val /= val2;
    }
    return val;
}

int factor(string& s, int& i) {
    if (isdigit(s[i])) return number(s, i);
    ++i;
    int res = expr(s, i);
    ++i;
    return res;
}

int number(string& s, int& i) {
    int res = s[i++] - '0';
    while (isdigit(s[i])) res = res * 10 + s[i++] - '0';
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        s = s.substr(0, s.size() - 1);
        int j = 0;
        cout << expr(s, j) << endl;
    }
}
