#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
ll inf = llmax / 2;
double eps = 1e-11;

string S = "12+1290";
int cur = 0;

int digit() {
    assert(isdigit(S[cur]));
    int n = S[cur] - '0';
    cur++;
    return n;
}

ll number() {
    ll n = digit();
    while (cur < S.size() && isdigit(S[cur])) {
        n = n * 10 + digit();
    }
    return n;
}

ll expression();

ll factor() {
    if (S[cur] != '(') {
        return number();
    }
    cur++;
    int n = expression();
    assert(S[cur] == ')');
    cur += 1;
    return n;
}

ll term() {
    ll a = factor();
    while (cur < S.size() && (S[cur] == '*' || S[cur] == '/')) {
        char op = S[cur];
        cur++;
        ll b = factor();
        if (op == '*') {
            a *= b;
        } else {
            a /= b;
        }
    }
    return a;
}

ll expression() {
    ll a = term();
    while (cur < S.size() && (S[cur] == '+' || S[cur] == '-')) {
        char op = S[cur];
        cur++;
        ll b = term();
        if (op == '+') {
            a += b;
        } else {
            a -= b;
        }
    }
    return a;
}

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> S;
        cur = 0;
        ll ans = expression();
        cout << ans << endl;
    }
}

