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


typedef string::const_iterator State;


int expression(State &begin);


int number(State &begin)
{
	int ret = 0;
	
	for(; isdigit(*begin); begin++) {
		ret = ret * 10 + *begin - '0';
	}

	return ret;
}

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

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

	while(true) {
		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);

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

	return ret;
}


int main()
{
	int N;
	cin >> N;
	cin.ignore();
		
	for (int i = 0; i < N; i++) {
		string s;
		getline(cin, s);

		State begin = s.begin();
		cout << expression(begin) << endl;
	}
	
	return 0;
}