#include <iostream>
#include <vector>
#include <sstream>
#include <cctype>
using namespace std;

typedef string::const_iterator State;

int factor(State &begin);

int number(State &begin) {
	int ret = 0;

	while(isdigit(*begin)) {
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}

	return ret;
}

int term(State &begin){
	int ret = factor(begin);

	for(;;){
		if(*begin == '*'){
			begin++;
			ret *= factor(begin);
		} else if (*begin == '/') {
			begin++;
			ret /= factor(begin);
		} else {
			break;
		}
	}

	return ret;
}

int expression (State &begin) {
	int ret = term(begin);

	for (;;) {
		if(*begin == '+') {
			begin++;
			ret += term(begin);
		} else if (*begin == '-') {
			begin++;
			ret -= term(begin);
		} else {
			break;
		}
	}

	return ret;
}

int factor (State &begin) {
	if(*begin == '(') {
		begin++;
		int ret = expression(begin);
		begin++;
		return ret;
	} else {
		return number(begin);
	}
}

int main(){
	int n;
	cin >> n;
	for(;n;n--){
		string s;
		cin >> s;
		State begin = s.begin();
		int ans = expression(begin);
		cout << ans << endl;
	}
	return 0;
}