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

string s;
int N;
int c;

int expr();
int term();
int factor();
int num();

void debug(string text){
	return;
	cout << text + " ";
	for(int i = 0; i < N; i++){
		if(i == c) cout << '[' << s[i] << ']';
		else cout << s[i];
	}
	cout << endl;
}

int expr(){
	debug("expr");
	int x = term();
	while(c < N && (s[c] == '+' || s[c] == '-')){
		if(s[c] == '+'){
			c++;
			x += term();
		}
		else{
			c++;
			x -= term();
		}
	}
	return x;
}

int term(){
	debug("term");

	int x = factor();
	while(c < N && (s[c] == '*' || s[c] == '/')){
		if(s[c] == '*'){
			c++;
			x *= factor();
		}
		else{
			c++;
			x /= factor();
		}
	}
	return x;
}

int factor(){
	debug("factor");

	if(s[c] == '('){
		c++;
		int ret = expr();
		assert(s[c] == ')');
		c++;
		return ret;
	}
	return num();
}

int num(){
	debug("num");

	int ret = 0;
	while(c < N && isdigit(s[c])){
		ret = ret * 10 + s[c] - '0';
		c++;
	}
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int n;
	cin >> n;
	while(n--){
		cin >> s;
		s.pop_back();
		N = s.size();
		c = 0;
		cout << expr() << endl;
	}
}