#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cassert>

using namespace std;

#define REP(var, count) for(int var=0; var<count; var++)

const char op[] = "()*/+-=N";


string line;
int cur;
char readchar() {
	return line[cur++];
}
char peek() {
	return line[cur];
}


int digit() {
	return readchar() - '0';
}
int number() {
	int n = digit();
	while ( peek() >= '0' && peek()<='9' ) {
		n = n*10 + digit();
	}
	return n;
}

int expression();
int factor() {
	if ( peek() != '(' ) { return number(); }
	assert( readchar() == '(' );
	int ret = expression();
	assert( readchar() == ')' );
	
	return ret;
}

int term() {
	int ret = factor();
	while( peek() == '*' || peek() == '/' ) {
		char op = readchar();
		int fac = factor();
		
		if ( op == '*' ) { ret *= fac; }
		else { ret /= fac; }
	}
	
	return ret;
}

int expression() {
	int ret = term();
	while( peek() == '+' || peek() == '-' ) {
		char op = readchar();
		int ter = term();
		
		if ( op == '+' ) { ret += ter; }
		else { ret -= ter; }
	}
	
	return ret;
}

int main(void) {
	int N;
	cin >> N;
	while(N--) {
		cin >> line;
		cur = 0;
		
		cout << expression() << endl;
	}

}