#include <iostream>
#include <vector>

using namespace std;

int eval(const string & expr) {
	int left = 0;
	int right = 0;
	int mdtemp = 0;
	int ev_idx = 0;
	int sign = 1; // 1=+, -1=-
	char c, cc;

	// 項の処理
	while((c = expr[ev_idx++]) != '\0') {
		if(c == '+' || c == '-') {
			left += sign * right;
			right = 0;
			if(c == '+') sign = 1;
			else sign = -1;
		} else if(c == '*' || c == '/') { // if mul,div
			mdtemp = 0;
			while(1) {
				if((cc = expr[ev_idx++]) == '\0' || cc == '+' || cc == '-' || cc == '*' || cc == '/') {
					ev_idx--;
					break;
				}
				if(cc == '(') {
					int clen = 0;
					int cstrt = ev_idx;
					while(expr[ev_idx++] != ')') clen++;
					string ceval = expr.substr(cstrt, clen);
					mdtemp = eval(ceval);
				} else {
					mdtemp *= 10;
					mdtemp += (int)(cc - '0');
				}
			}
			if(c == '*') right *= mdtemp;
			else right /= mdtemp;
		} else if(c == '(') {
			int clen = 0;
			int cstrt = ev_idx;
			while(expr[ev_idx++] != ')') clen++;
			string ceval = expr.substr(cstrt, clen);
			right = eval(ceval);
		} else { // if numbers
			right *= 10;
			right += (int)(c - '0');
		}
	}
	left += sign * right;
	
	return left;
}

int main() {
	int n;
	cin >> n;
	
	vector<int> anss(n);

	for(int i=0;i<n;i++) {
		string expr;
		cin >> expr;
		int ans;
		ans = eval(expr);
		anss[i] = ans;
	}
	for(auto it = anss.begin(); it != anss.end(); it++) {
		cout << *it << endl;
	}
	
	return 0;
}

