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

typedef pair<int,char> P;

int calc(int a, int b, char ope) {
	int ret;
	switch(ope) {
	case '+': ret = a + b; break;
	case '-': ret = a - b; break;
	case '*': ret = a * b; break;
	case '/': ret = a / b; break;
	default: ret = 0;
	}
	return ret;
}

int main() {
	int n, v, sv; string s; char c, ope, sope;
	stack<P> st;
	cin >> n;
	while(n--) {
		cin >> s; v = 0; ope = '#';
		for(int i=0; i<(signed)s.length(); ++i) {
			c = s[i];
			if('0'<=c && c<='9') {
				
				v = v*10+(int)(c-'0');
			}else if(c=='('){
				st.push(P(0,'#'));
				v = 0;
			}else if(c==')'){
				while(!st.empty()) {
					sv=st.top().first; sope=st.top().second; st.pop();
					if(sope=='#') break;
					v = calc(sv, v, sope);
				}
			}else {
				if(c=='=') break;
				ope = c;
				if(st.empty()) {
					st.push(P(v,ope)); v=0;
				}else {
					sv=st.top().first; sope=st.top().second;
					if(((sope=='+'||sope=='-')&&(ope=='*'||ope=='/'))||sope=='#') {
						st.push(P(v,ope)); v=0;
					}else {
						v = calc(sv, v, sope);
						st.pop();
						st.push(P(v,ope));
						v=0;
					}
				}
			}
		}
		while(!st.empty()) {
			sv=st.top().first; sope=st.top().second; st.pop();
			v = calc(sv, v, sope);
		}
		cout << v << endl;
	}
	return 0;
}