#include <cmath>
#include <cassert>
#include <iostream>

using namespace std;

string S;
size_t cur = 0;

int digit() {
	int n;
	assert(isdigit(S[cur]));
	n = S[cur] -'0';
	++cur;
	return n;
}

int number() {
	int n = digit();
	while (cur < S.size() && isdigit(S[cur])) {
		n = n*10 + digit();
	}
	return n;
}

int expression();
int factor() {
	int n;
	if (S[cur] != '(') n = number();
	else {
		++cur;
		n = expression();
		assert(S[cur] == ')');
	}
	return n;
}

int term() {
	int t = factor();
	while (cur < S.size() && (S[cur] == '*' || S[cur] == '/')) {
		char op = S[cur++];
		int b = factor();
		if(op == '*') t *= b; else t /= b;
	}
	return t;
}


/*int expression() {
	int sum = number();
	while (S[cur] == '+' || S[cur] == '-') {
		char op = S[cur++];
		int b = number();
		if(op == +) sum += b;	else return sum -= b;
	}
	return sum;
}*/

int expression() {
	int sum = term();
	while (cur < S.size() && (S[cur] == '+' || S[cur] == '-')) {
		char op = S[cur++];
		int b = term();
		if(op == '+') sum += b; else sum -= b;
	}
	return sum;
}


int main() {
	int N;
	cin >> N;
	for (int i=0; i<N; ++i) {
		cur = 0;
		cin >> S;
		S.resize(S.size()-1);
		cout << expression() << endl;
	}
	return 0;
}