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

using namespace std;


// ?????????????§?????§£???????????????????????¨???????????????
class MathExpress
{
private:
    string m_express;
    size_t m_cur = 0;

public:
    MathExpress(string str) : m_express(str) 
    {
        m_express.resize(m_express.size() - 1);
    }

    int digit(); // ???????????°???
    int number(); // ??°??????????????°????????´???
    int term();
    int factor(); 
    int expression();
};


int MathExpress::digit()
{
    assert(isdigit(m_express.at(m_cur)));

    int n = m_express.at(m_cur) - '0';

    m_cur += 1;

    //cout << "digit: " << n << endl;

    return n;
}


int MathExpress::number()
{
    int num = digit();

    while ( m_cur < m_express.size() && isdigit(m_express.at(m_cur)) )
    {
        num = num * 10 + digit();
    }

    //cout << "number: " << num << endl;

    return num;
}


int MathExpress::term()
{
    int left = factor();

    while (m_cur < m_express.size() 
         && (m_express.at(m_cur) == '*' || m_express.at(m_cur) == '/'))
    {
        char op = m_express.at(m_cur++);

        //cout << op << endl;

        int right = number();

        switch (op) {
            case '*':
                left *= right;
                break;
            case '/':
                left /= right;
                break;
            default:
                break;
        }

    }

    //cout << "term: " << left << endl;

    return left;
}


int MathExpress::expression()
{
    int left = term();

    while (m_cur < m_express.size() 
         && (m_express.at(m_cur) = '+' || m_express.at(m_cur) == '-'))
    {
        //cout << m_cur << " " << m_express.at(m_cur) << endl;
        char op = m_express.at(m_cur);

        m_cur += 1;

        //cout << op << endl;
        //cout << "hoge" << endl;

        int right = term();

        //cout << "hoge" << endl;

        switch (op) {
            case '+':
                //cout << "hoge" << endl;
                left += right;
                break;
            case '-':
                left -= right;
                break;
            default:
                //cout << "hoge" << endl;
                break;
        }

        //cout << "left : right = " << left << " " << right << endl;
    }

    return left;
}


int MathExpress::factor()
{
    if (m_express.at(m_cur) != '(') return number();

    m_cur += 1;

    int exp = expression();

    assert (m_express.at(m_cur) == ')');

    m_cur += 1;

    return exp;
}


int main()
{
    int data_num;
    
    cin >> data_num;
    
    cin.clear();

    string val; 
    for (int i = 0; i < data_num; ++i) {
        cin >> val;

        MathExpress mathexp(val);
        cout << mathexp.expression() << endl;
    }
    
    return 0;
}