#include <iostream>
#include <string>
#include <stack>
#include <map>
#include <vector>

using namespace std;

int main(){
    int n;
    string q, a, sop;
    stack<int> numstack;
    stack<string> opstack;
    map<string, int> oprank;
	vector<string> exq;
    oprank["/"] = oprank["*"] = 2;
    oprank["+"] = oprank["-"] = 1;
	oprank["("] = 0;
    cin >> n;
    for(int i(0);i < n;++i){
        cin >> q;
		exq.clear();
        a = "";
        for(int j(0);j < q.length();++j){
            if(q[j] < '0' || '9' < q[j]){
                if(a.length() > 0) exq.push_back(a);
                a = "";
				sop = string(1, q[j]);
                if(opstack.empty()){
					opstack.push(sop);
					continue;
				}
				if(sop == ")"){
					while(opstack.top() != "("){
						exq.push_back(opstack.top());
						opstack.pop();
					}
					opstack.pop();
				}
				else if(sop == "(") opstack.push(sop);
				else if(sop == "="){
					while(!opstack.empty()){
						exq.push_back(opstack.top());
						opstack.pop();
					}
				}
				else if(oprank[sop] <= oprank[opstack.top()]){
					while(!opstack.empty() && oprank[sop] <= oprank[opstack.top()]){
						exq.push_back(opstack.top());
						opstack.pop();
					}
					opstack.push(sop);
				}
				else opstack.push(sop);
            }
            else a += q[j];
        }
		for(string s : exq){
			if(s[0] < '0' || '9' < s[0]){
				int x, y;
				y = numstack.top();
				numstack.pop();
				x = numstack.top();
				numstack.pop();
				if(s == "+"){
					numstack.push(x + y);
				}
				else if(s == "-"){
					numstack.push(x - y);
				}
				else if(s == "*"){
					numstack.push(x * y);
				}
				else if(s == "/"){
					numstack.push(x / y);
				}
			}
			else numstack.push(stoi(s));
		}
		cout << numstack.top() << endl;
		numstack.pop();
    }
    return 0;
}