#include <iostream>
#include <stack>

using namespace std;

int pri(char ch) 
{
    if (ch == '*' || ch == '/')
        return 2;
    if (ch == '+' || ch == '-')
        return 1;
    else
        return 0;
}

int main()
{
    int n;

    cin >> n;

    while (n--) {
        string exp, cha;
        stack<char> pol;
        stack<int> cal;

        cin >> exp;
        for (int i = 0; i < exp.size() - 1; i++) {
            if ('0' <= exp[i] && exp[i] <= '9') {
                while (true) {
                    cha.push_back(exp[i]);
                    if ('0' > exp[i + 1] || exp[i + 1] > '9') {
                        cha.push_back('.');
                        break;
                    }
                    else
                        i++;
                }
            }
            else if (exp[i] == '(')
                pol.push(exp[i]);
            else if (exp[i] == ')') {
                while (true) {
                    if (pol.top() == '(') {
                        pol.pop();
                        break;
                    }
                    cha.push_back(pol.top());
                    pol.pop();

                }
            }
            else {
                while (!pol.empty()) {
                    if (pri(exp[i]) < pri(pol.top())) {
                        cha.push_back(pol.top());
                        pol.pop();
                    }
                    else 
                        break;
                }
                pol.push(exp[i]);
            }
        }

        while (!pol.empty()) {
            cha.push_back(pol.top());
            pol.pop();
        }

        for (int i = 0; i < cha.size(); i++) {
            if ('0' <= cha[i] && cha[i] <= '9') {
                int tmp = cha[i] - '0';

                while (true) {
                    i++;
                    if (cha[i] == '.') 
                        break;
                    tmp *= 10;
                    tmp += cha[i] - '0';
                }
                cal.push(tmp);
            }
            else {
                int a, b;

                b = cal.top();
                cal.pop();
                a = cal.top();
                cal.pop();

                if (cha[i] == '*') 
                    cal.push(a * b);
                else if (cha[i] == '/') 
                    cal.push(a / b);
                else if (cha[i] == '+') 
                    cal.push(a + b);
                else if (cha[i] == '-') 
                    cal.push(a - b);
            }
        }
        cout << cal.top() << endl;
    }