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

string S;
size_t cur=0;

int term();
int expression();

int digit(){
	assert(isdigit(S[cur])); 
	int 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 factor() {
	if (S[cur] != '(') return number();
	cur += 1;
	int n = expression();
	assert(S[cur] == ')');
	cur += 1;
	return n;
}

int term(){
	int sum = factor();
	while(S[cur] == '*' || S[cur] == '/'){
		char op = S[cur];
		cur += 1;
		int b = factor();
		if( op == '*')
			sum*=b;
		else {
			assert(b);
			sum/=b;
		}
	}
	return sum;
}

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



int main(void){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> S;
		cur=0;
		int r;
		r=expression();
		cout << r << endl;
	}
return 0;
}