#include <iostream>
#include <string>
#include <cctype>
#include <cassert>

using namespace std;

string S;
size_t cur = 0;

char readchar();
char peek();
int digit();
int number();
int expression();
int parse();

int main() {
	int count;
	cin >> count;
	for(int i=0;i<count;i++) {
		cur = 0;
		
		cin >> S;
		//cout << S << endl;
		S.resize(S.size()-1);
		int a = parse();
		cout << a << endl;
	}
	

}


// 1 ??????????????§ cur ????????????
// ??????:?¬???? readchar ??§???????¬???????????????????
char readchar() {
	assert(cur < S.size());
	char ret = S[cur];
	cur += 1;
	return ret;
// return S[cur++]; ??¨????????§???????????¨?????§??????
}
char peek() { // 1 ??????????????? cur ???????????????
	//assert(cur < S.size());
	return S[cur];
}

int digit() {
	assert(isdigit(peek())); // S[cur] ?????°?????§???????????¨????¢????
	int n = readchar() - '0'; // ???0??? ??? 0 ?????????
	return n;
}
int number() {
	int n = digit();
	while (cur < S.size() && isdigit(peek())) // ?¬??????°?????? 1 ????????????
	n = n*10 + digit();
	return n;
}
int expression();

int factor() {
	if (peek() != '(') return number();
	cur += 1;
	int n = expression();
	assert(peek() == ')');
	cur += 1;
	return n;
}

int term() {
	int a = factor();
	while (cur < S.size() && (peek() == '*' || peek() == '/')) {
		char op = readchar();
		int b = factor();
		if (op == '*') a *= b; else a /= b;
	}
	return a;
}

int expression() {
	int a = term();
	while(cur < S.size() && (peek() == '+' || peek() == '-')) {
		char op = readchar();
		int b = term();
		assert((op == '+') || (op == '-'));
		if(op == '+') {
			a+=b;
		} else {
			a-=b;
		}
	}
	return a;
}

int parse() {
	return expression();
}