#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int calc(string s){
    while(1){
        vector<pair<int, int>> vv;
        int depth = 0;
        for(int i = 0; i < s.size(); i++){
            if(s[i] == '('){
                vv.push_back(pair<int, int>(i, ++depth));
            }else if(s[i] == ')'){
                --depth;
            }
        }
        if(vv.size() != 0){
            sort(vv.begin(), vv.end(), [](auto a, auto b){return a.second != b.second ? a.second > b.second : a.first < b.first;});
            int pos;
            for(pos = vv[0].first; s[pos] != ')'; pos++);
            int ret = calc(s.substr(vv[0].first + 1, pos - vv[0].first - 1));
            string t = s.substr(0, vv[0].first) + to_string(ret) + s.substr(pos + 1);
            s = t;
            cout << s << endl;
        }else{
            while(1){
                map<char, vector<int>> m;
                for(int i = 0; i < s.size(); i++){
                    if(s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/') m[s[i]].push_back(i);
                }
                vector<int> v;
                if(m.find('*') != m.end() || m.find('/') != m.end()){
                    for(int pos : m['*']) v.push_back(pos);
                    for(int pos : m['/']) v.push_back(pos);
                }else{
                    for(int pos : m['+']) v.push_back(pos);
                    for(int pos : m['-']) v.push_back(pos);
                }
                if(v.size() == 0 || (v.size() == 1 && v[0] == 0)) break;
                sort(v.begin(), v.end());
                string t;
                int pos = v[0];
                string num[2];
                int tmp;
                for(int j = pos - 1; 0 <= j; j--){
                    if('0' <= s[j] && s[j] <= '9'){
                        num[0] += s[j];
                    }else{
                        for(int k = 0; k <= j; k++){
                            t += s[k];
                        }
                        break;
                    }
                }
                for(int j = pos + 1; j <= s.size(); j++){
                    if('0' <= s[j] && s[j] <= '9'){
                        num[1] += s[j];
                    }else{
                        tmp = j;
                        break;
                    }
                }
                int add;
                switch(s[pos]){
                    case '+':
                        add = stoi(num[0]) + stoi(num[1]);
                        break;
                    case '-':
                        add = stoi(num[0]) - stoi(num[1]);
                        break;
                    case '*':
                        add = stoi(num[0]) * stoi(num[1]);
                        break;
                    case '/':
                        add = stoi(num[0]) / stoi(num[1]);
                        break;
                }
                t += to_string(add);
                for(int j = tmp; j < s.size(); j++) t += s[j];
                s = t;
            }
            return stoi(s);
        }
    }
}
    
int main(){
    int N;
    cin >> N;
    for(int pomu = 0; pomu < N; pomu++){
        string s;
        cin >> s;
        s = s.substr(0, s.size() - 1);
        cout << calc(s) << endl;
    }
    return 0;
}
