#include <bits/stdc++.h>
using namespace std;

int Num();
int Term();
int Exp();

int ite;
string s;

int Num() {
	int res = 0;
	while (isdigit(s[ite])) {
		res = res * 10 + s[ite] - '0';
		ite++;
	}
	return res;
}

int Term() {
	int res = Num();
	while (true) {
		if (s[ite] == '*') {
			ite++;
			if (s[ite] == '(') {
				ite++;
				res *= Exp();
				assert(s[ite] == ')');
				ite++;
			}
			else {
				res *= Num();
			}
		}
		else if (s[ite] == '/') {
			ite++;
			if (s[ite] == '(') {
				ite++;
				res /= Exp();
				assert(s[ite] == ')');
				ite++;
			}
			else {
				res /= Num();
			}
		}
		else {
			break;
		}
	}
	return res;
}

int Exp() {
	int res = Term();
	while (s[ite] != '=' && s[ite] != ')') {
		if (s[ite] == '+') {
			ite++;
			res += Term();
		}
		else if(s[ite] == '-') {
			ite++;
			res -= Term();
		}
		else {
			cout << "abyaaaa" << endl;
			assert(false);
		}
	}
	return res;
}

int main()
{
	int n;
	cin >> n;
	while (n--) {
		cin >> s;
		ite = 0;
		cout << Exp() << endl;
	}
	return 0;
}