#include<iostream>
#include<cassert>
#include<algorithm>

using namespace std;

char *pt;
int parseAtom();
int parseExpr();
int parseTerm();


int parseAtom(){
	if('0' <= *pt && *pt <= '9'){
		int x = *pt - '0';
		pt++;
		while('0' <= *pt && *pt <= '9'){
			x = x * 10 + *pt - '0';
			pt++;
		}
		return x;
	}
	if('(' == *pt){
		pt++;
		int x = parseExpr();
		assert(*pt == ')');
		pt++;
		return x;
	}
	assert(false);
	return -1;
}
int parseExpr(){
	int x = parseTerm();
	while(*pt == '+' || *pt == '-'){
		if(*pt == '+'){
			pt++;
			x += parseTerm();
		}else {
			pt++;
			x -= parseTerm();
		}
	}
	return x;
}
int parseTerm(){
	int x = parseAtom();
	while(*pt == '*' || *pt == '/'){
		if(*pt == '*'){
			pt++;
			x *= parseAtom();
		} else{
			x /= parseAtom();
		}
	}
	return x;
}
int main(void){
	int n ;
	cin>>n;
	for(int i = 0 ; i < n ;  i ++){
		static char expr[200];
		cin>>expr;
		pt=expr;
		int x = parseExpr();
		assert(*pt == '=');
		cout<<x<<endl;
	}
	return 0;
}