#include <iostream>

using namespace std;

char num[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

int exp(char a[]);
int term(char a[]);
int factor(char a[]);
int p;

bool func(char a)
{
	for(int i = 0; i < 10; i++){
		if(a == num[i]){
			return true;
		}
	}
	return false;
}

int exp(char a[])
{
	int x = term(a);
	while(a[p] == '+' || a[p] == '-'){
		if(a[p] == '+'){
			p++;
			x += term(a);
		} else {
			p++;
			x -= term(a);
		}
	}
	
	return x;
}

int term(char a[])
{
	int x = factor(a);
	while(a[p] == '*' || a[p] == '/'){
		if(a[p] == '*'){
			p++;
			x *= factor(a);
		} else {
			p++;
			x /= factor(a);
		}
	}
	
	return x;
}

int factor(char a[])
{
	while(a[p] == '(' || func(a[p])){
		if(a[p] == '('){
			p++;
			return exp(a);
		} else {
			for(int i = 0; i < 10; i++){
				if(a[p] == num[i]){
					p++;
					return i;
				}
			}
		}
	}
	
	return 0;
}

int main(int argc, char **argv)
{
	int n;
	char a[100];
	
	cin >> n;
	while(n--){
		scanf("%s", a);
		p = 0;
		cout << exp(a) << endl;
	}
	
	return 0;
}