#include <stdio.h>
#include <assert.h>

char buf[128];
int pos;
#define NOW (buf[pos])

bool isdigit(char c) {
	return ('0' <= c && c <= '9');
}

int digit() {
	if ( !isdigit(NOW) ) {
		fprintf(stderr, "%c: ", NOW);
		assert( isdigit(NOW) );
	}
	int ret = NOW - '0';
	pos++;
	
	return ret;
}
int number() {
	int ret = digit();
	while( isdigit(NOW) ) {
		ret = ret*10 + digit();
	}
	return ret;
}

int expression();
int factor() {
	if ( NOW=='(' ) {
		pos++;
		int ret = expression();
		assert(NOW==')');
		pos++;
		
		return ret;
	}
	
	return number();
}

int term() {
	int ret = factor();
	while ( NOW=='*' || NOW=='/' ) {
		char oper = NOW;
		pos++;
		int right = factor();
		if ( oper == '*' ) {
			ret *= right;
		} else {
			ret /= right;
		}
	}
	
	return ret;
}

int expression() {
	int ret = term();
	while ( NOW=='+' || NOW=='-' ) {
		char oper = NOW;
		pos++;
		int right = term();
		if ( oper == '+' ) {
			ret += right;
		} else {
			ret -= right;
		}
	}
	
	return ret;
}


int main(void) {

	int set;
	scanf("%d", &set);
	
	while(set--) {
		scanf("%s", buf);
		pos = 0;
		printf("%d\n", expression());
	}
	
}