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

int p;
string exp;

int term();
int expression();
int factor();


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


int term(){
	int value;
	value=factor();
	while(exp[p]=='*' || exp[p]=='/'){
		if(exp[p]=='*'){
			p++;
			value*=factor();
		}
		else{
			p++;
			value/=factor();
		}
	}

	return value;
}

int factor(){
	int value=0;
	if(exp[p]=='('){
		value=expression();
	}
	else{
		while(isdigit(exp[p])){
			value=value*10+exp[p++]-'0';
		}
	}
	return value;
}



int main()
{
	int i,c;
	cin>>c;
	for(i=0;i<c;i++){
		cin>>exp;
		p=0;
		cout<<expression()<<"\n";
		}
	cout<<"\n";
	return 0;
}