#include <iostream>
#include <string>
#include <cctype>
using namespace std;
typedef string::const_iterator State;

int number(State &begin);
int term(State &begin);
int expression(State &begin);
int factor(State &begin);

int number(State &begin) {
	int ret = 0;
	
	while (isdigit(*begin)) {
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}
	// cout << "number :: " << ret << endl;
	return ret;
}
int term(State &begin) {
	int ret = factor(begin);
	
	while(1) {
		if (*begin == '*') {
			begin++;
			// cout << "go factor // *" << endl;
			ret *= factor(begin);
		}
		else if (*begin == '/') {
			begin++;
			// cout << "go factor // /" << endl;
			ret /= factor(begin);
		}
		else break;
	}
	// // cout << "term :: " << ret << endl;
    return ret;
}
int expression(State &begin) {
	int ret = term(begin);
	
	while(1) {
		if (*begin == '+') {
			begin++;
			// // cout << "go term // +" << endl;
			ret += term(begin);
		}
		else if (*begin == '-') {
			begin++;
			// // cout << "go term // -" << endl;
			ret -= term(begin);
        }
        else break;
	}
	// // cout << "expression :: " << ret << endl;
	return ret;
}
int factor(State &begin) {
	if (*begin == '(') {
		begin++; 
		// // cout << "go expression" << endl;
		int ret = expression(begin);
		// // cout << "factor :: " << ret << endl;
		begin++;
		return ret;
	}
	else return number(begin);
}

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