#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

typedef string::const_iterator State;
class ParseError {};

struct Parser {
    // エラー検出
    void consume(State &begin, char expected) {
        if(*begin == expected) begin++;
        else {
            cerr << "Expected '" << expected << "' but got '" << *begin << "'" << endl;
            cerr << "Rest string is '";
            while(*begin) {
                cerr << *begin++;
            }
            cerr << "'" << endl;
            throw ParseError();
        }
    }

    // 数字の列をパースして、その数を返す
    int number(State &begin) {
        int ret = 0;
        while(isdigit(*begin)) {
            ret *= 10;
            ret += (*begin - '0');
            begin++;
        }
        return ret;
    }

    // 括弧か数をパースして、その評価結果を返す
    int factor(State &begin) {
        if(*begin == '(') {
            consume(begin, '(');    // '('を飛ばす
            int ret = expression(begin);
            consume(begin, ')');    // ')'を飛ばす
            return ret;
        }else return number(begin);
    }

    // 乗算除算の式をパースして、その評価結果を返す
    int term(State &begin) {
        int ret = factor(begin);
        while(1) {
            if(*begin == '*') {
                consume(begin, '*');
                ret *= factor(begin);
            }else if(*begin == '/') {
                consume(begin, '/');
                ret /= factor(begin);
            }else break;
        }
        return ret;
    }

    // 四則演算の式をパースして、その評価結果を返す
    int expression(State &begin) {
        int ret = term(begin);
        while(1) {
            if(*begin == '+') {
                consume(begin, '+');
                ret += term(begin);
            }else if(*begin == '-') {
                consume(begin, '-');
                ret -= term(begin);
            }else break;
        }
        return ret;
    }
};

int main() {
    int n; cin >> n;
    cin.ignore();
    for(int i = 0; i < n; ++i) {
        Parser ps;
        string s;
        getline(cin, s);

        State begin = s.begin();
        int ans = ps.expression(begin);
        ps.consume(begin, '=');
        cout << ans << endl;
    }
}
