#include<iostream>
#include<vector>
#include<string>
using namespace std;

int calculation( int a, int b, char c )
{
    if( c == '+' )
        return a + b;
    else if( c == '-' )
        return a - b;
    else if( c == '*' )
        return a * b;
    else if( c == '/' )
        return a / b;
    else
        return a;
}

int main()
{
    int n;
    vector<int> d, p;
    vector<char> f;
    string str;


    cin >> n;

    for( int k = 0; k < n; k++ )
    {
        cin >> str;

        int plus = 0;
        for( int i = 0; i < str.size(); i++ )
        {
            int a = str[i] - '0', j = i;
            while( 0 <= a && a < 10 )
            {
                j++;
                a = str[j] - '0';
            }
            int sum = 0, mul = 1;
            for( int s = 0; s < j - i; s++ )
            {
                sum += ( str[j-(s+1)] - '0' ) * mul;
                mul *= 10;
            }
            if( 0 <= str[i] - '0' && str[i] - '0' < 10 )
            {
                d.push_back(sum);
                while( mul != 1 )
                {
                    i++;
                    mul /= 10;
                }
                i--;
            }
            else
            {
                if( str[i] == '+' || str[i] == '-' )
                    p.push_back( plus + 1 );
                else if( str[i] == '*' || str[i] == '/' )
                    p.push_back( plus + 2 );
                else if( str[i] == '(' )
                    plus += 3;
                else if( str[i] == '=' )
                    p.push_back(0);
                else
                    plus -= 3;
                if( str[i] != '(' && str[i] != ')' )
                    f.push_back(str[i]);
            }
        }

        // for( int i = 0; i < d.size(); i++ )
        //     cout << d[i] << " ";
        // cout << endl;

        // for( int i = 0; i < p.size(); i++ )
        //     cout << p[i] << " ";
        // cout << endl;

        // for( int i = 0; i < f.size(); i++ )
        //     cout << f[i] << " ";
        // cout << endl;

        while( f[0] != '=' )
        {
            for( int i = 0; i < p.size() - 1; i++ )
            {
                if( p[i] > p[i+1] )
                {
                    d[i] = calculation( d[i], d[i+1], f[i] );
                    f[i] = f[i+1];
                    p[i] = p[i+1];

                    int s = i;
                    while( s + 2 < p.size() )
                    {
                        d[s+1] = d[s+2];
                        f[s+1] = f[s+2];
                        p[s+1] = p[s+2];
                        s++;
                    }
                }
            }
        }
        cout << d[0] << endl;
    }
    return 0;
}
