#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define repr(i ,n) for(int i=n;i>(int)(n);--i)
#define rep1(i ,n) for(int i=1;i<=(int)(n);++i)
#define ALL(a) a.begin(), a.end()
#define RSORT(a) sort(ALL(a),greater<>())
#define SORT(a) sort(ALL(a))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define PRINT(x) cout << (x) << endl
#define ENDL printf("\n")
using namespace std;
typedef long long int i64;
typedef unsigned long long u64;
template<class T> using V = vector<T>;
using VI = V<int>;
const int INF = 2e9;
const i64 MOD = 1e9 + 7;
 
template <class T> inline bool chmin(T& a, T b){if(a>b){a=b; return true;} return false;}
template <class T> inline bool chmax(T& a, T b){if(a<b){a=b; return true;} return false;}
struct Init_On{
    Init_On(){
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(16);
    }
};
 
int calc(string& s){
    int num_of_op = 0;
    s.insert(s.begin(),'s');
    int len = s.size();
    string operand;
    operand.clear();
    rep( i , len){
        if((s[i] > '9' || s[i] < '0') && s[i]!='s') {
            if( s[i] == '-' && (s[i-1] >'9' || s[i-1] <'0' && i-1 >=0 )) continue;
            ++num_of_op;
        }
    }
    vector<int> num(num_of_op+1);
    vector<char> op(num_of_op);
    int x = 0;
    rep(i , len){
        if((s[i] > '9' || s[i] < '0') && s[i] != 's'){
            if(s[i] == '-' && (s[i-1] > '9' || s[i-1] < '0' && i-1 >=0)) continue;
            op[x++] = s[i];
        }
    }
    s += 'e';
    int j = 0;
    bool flag = false;
    for( int i = 0 ; i < num_of_op + 1  ; ++i){
        for( ; (s[j] <= '9' && s[j] >= '0') || s[j] == 's' || flag ; ++j){
            if(s[j] =='s' && s[j+1] == '-') { operand += '-'; ++j; continue; }
            if((s[j-1] >'9' || s[j-1] < '0' ) && s[j] == '-' && j-1 >= 0 ) { operand += '-'; flag = true; continue;}
            if(s[j] != 's' && ( s[j]<='9' && s[j]>='0') ) { operand += s[j]; flag = false; }
        }
        num[i] = stoi(operand);
        operand.clear();
        ++j;
        if(s[j]=='-') flag = true;
    }
    int muldiv = 0 , sumdiff = 0;
    rep( i , num_of_op){
        
        if (op[i] == '+' || op[i] == '-') ++sumdiff;
        else if (op[i] == '*' || op[i] == '/') ++muldiv;
    }
    while(muldiv){
        rep( i , num_of_op){
            if(op[i] == '*'){
                num[i+1] = num[i] * num[i+1];
                num.erase(num.begin()+i); op.erase(op.begin()+i); --i; --num_of_op;
                --muldiv;
            } else if(op[i] == '/'){
                num[i+1] = num[i] / num[i+1];
                num.erase(num.begin()+i); op.erase(op.begin()+i); --i; --num_of_op;
                --muldiv;
            }
        }
    }
    while(sumdiff){
        rep(i , num_of_op){
            if( op[i] == '+'){
                { num[i+1] = num[i] + num[i+1]; num.erase(num.begin()+i); op.erase(op.begin()+i); --num_of_op; --i; --sumdiff; }
            }
            else if (op[i] == '-'){
                { num[i+1] = num[i] - num[i+1]; num.erase(num.begin()+i); op.erase(op.begin()+i); --num_of_op; --i; --sumdiff; }
            }
        }

    }
    return num[0];
}
 
signed main(){
    Init_On start;
    int n; cin >> n;
    int t = n;
    VI ans(t);
    while(t){
        string s; cin >> s;
        string tmp;
        auto itr = s.end(); --itr; s.erase(itr);
        int i , j;
        int num_br = 0;
        rep( k , s.size()) {
            if(s[k] == ')') ++num_br;
        }
        if( num_br == 0) { ans.push_back(calc(s)); --t; continue; }
        while(num_br){
            for( i = 0 ; i < s.size() ; ++i){
                if(s[i]==')'){
                    auto itr1 = s.begin();
                    rep( k , i) ++itr1;
                    s.erase(itr1);
                    j = i;
                    for( ; s[j]!='('; --j ){}
                    auto itr2 = s.begin();
                    rep( k , j) ++itr2;
                    s.erase(itr2);
                    break; 
                }
            }
                tmp = s.substr(j , i-j-1);
                tmp = to_string(calc(tmp));
                s.replace( j , i-j-1 , tmp);
                --num_br;
        }
        bool f = true;
        for(int i = 0 ; i < s.size() ; ++i){
            if(s[i]>'9' || s[i]<'0' ) f = false; 
        }
        if(f) ans.push_back(stoi(s)); 
        else ans.push_back(calc(s));
        --t;
    }
    reverse(ALL(ans));
    for(int i = n - 1 ; i >=0 ; --i) cout << ans[i] << endl;
}


Measured memory_bytes: 3312