#include <iostream>
#include <string>
#include <cctype>
#include <cassert>

using namespace std;

string Str;
unsigned int cur = 0;

int digit();
int number();
int term();
int facter();
int expression();

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cur = 0;
        cin >> Str;
        Str.resize(Str.size()-1);
        int ans = expression();
        cout << ans << endl;
    }
    return 0;
}

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

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

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

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

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