#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    int N;
    cin >> N;
    for(int pomu = 0; pomu < N; pomu++){
        string s;
        cin >> s;
        s = s.substr(0, s.size() - 1);
        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) 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;
        }
        cout << s << endl;
    }
    return 0;
}
