#include <iostream>
#include <cctype>
#include<cassert>
using namespace std;
size_t cur=0;
string S;



int digit(){
assert(isdigit(S[cur]));
int n=S[cur]-'0';
cur=cur+1;
return n;
}

int number(){
	int n=digit();
	while(cur<S.size() && isdigit(S[cur])){
		n=n*10+digit();
	}
	return n;
}

int expression();

int factor(){
	if(S[cur]!='(') return number();
	cur=cur+1;
	int n=expression();
	assert(S[cur]==')');
	cur=cur+1;
	return n;
}


int term(){
 int a=factor();
 while(cur<S.size() && (S[cur]=='*' || S[cur]=='/')){
 	char op = S[cur++];
 	int b= factor();
 	if (op== '*')a*=b;
 	else a/=b;
 }
return a;
}


int expression(){
	int a=term();
	while((S[cur]=='+'||S[cur]=='-')&&cur<S.size()){
		char op =S[cur++];
		int b=term();
		if (op=='+'){
			a=a+b;
		}
		else{
			a=a-b;
		}
	}
	return a;
}


int parse(){ return expression();}
int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
	cin>>S;
	cur=0;
	S.resize(S.size()-1);
int a=parse();
cout<<a<<endl;
}
	return 0;
}