#include <iostream>
#include <string>
#include <cassert>
#include <cctype>
using namespace std;

string S;
size_t cur = 0;
int parse();
int number();
int expression();
int factor();
char readchar();
char peek();

//------ number ------

int digit()
{
    int n = readchar() - '0';
    return n;
}

int number()
{
    int n = digit();
    while (peek() != '=' && isdigit(peek()))
    {
        n = n * 10 + digit();
    }
    return n;
}

//------ expression ------

int term()
{
    int a = factor();
    while (peek() != '=' && peek() != ')' && (peek() == '*' || peek() == '/'))
    {
        char op = readchar();
        int b = factor();

        if (op == '*')
            a *= b;
        else if (op == '/')
            a /= b;
    }
    return a;
}

int expression()
{
    int a = term();
    while (peek() != '=' && peek() != ')' && (peek() == '+' || peek() == '-'))
    {
        char op = readchar();
        int b = term();

        if (op == '+')
            a += b;
        else if (op == '-')
            a -= b;
    }
    return a;
}

int factor()
{
    if (peek() != '(')
        return number();
    cur += 1;
    int n = expression();
    assert(peek() == ')');
    cur += 1;
    return n;
}

//------ parse ------

int parse()
{
    cur = 0;
    return expression();
}

//------ READ ------

char readchar()
{
    char ret = S[cur++];
    return ret;
}
char peek()
{
    return S[cur];
}

//------------------

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