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

typedef string::const_iterator State;
int number(State &begin);
int factor(State &begin);
int expression(State &begin);
int term(State &begin);

int number(State &begin){		//数字
	int ret = 0;
	while (isdigit(*begin)){
		ret *= 10;
		ret += (*begin - '0');
		begin++;
	}
	return ret;
}
int factor(State &begin){		//括弧
	if (*begin == '(') return expression(begin);
	if (*begin == '-') return -1 * factor(begin);
	if (*begin == '+') return factor(begin);
	
	int ret = number(begin);
	begin--;
	return ret;
}
int term(State &begin){			//乗算除算
	int ret = factor(begin);
	while (1){
		if (*begin == '*') ret *= factor(++begin);
		else if (*begin == '/') ret /= factor(++begin);
		else break;
	}
	begin--;
	return ret;
}
int expression(State &begin){	//四則演算
	int ret = term(begin);
	while (1){
		if (*begin == '+') ret += term(++begin);
		else if (*begin == '-') ret -= term(++begin);
		else break;
	}
	return ret;
}

int main(void)
{
	int n;
	cin >> n;
	cin.ignore();
	for (int i = 0; i < n; i++){
		string str;
		getline(cin, str);
		
		State begin = str.begin();
		cout << expression(begin) << endl;
	}
	
	return 0;
}