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



int calculator(const string &s){
	int sta[100],sp=0;
	bool isnum[100];
	for(int i=0;i<s.size();){
		if(s[i]=='=')break;
		if(s[i]=='('){
			sta[sp]='(';
			isnum[sp++]=false;
			i++;
		}else if(s[i]==')'){
			int a,b;
			b=sta[--sp];
			while(sta[sp-1]!='('){
				char op=sta[--sp];
				a=sta[--sp];
				if(op=='+')b=a+b;
				else b=a-b;
			}
			sp--;
			while(sp&&!isnum[sp-1]&&(sta[sp-1]=='*'|| sta[sp-1]=='/') ){
				char op=sta[--sp];
				a=sta[--sp];
				if(op=='*')b=a*b;
				else b=a/b;
			}
			sta[sp]=b;
			isnum[sp++]=true;
			i++;
		}else if(s[i]=='+'||s[i]=='-'||s[i]=='*'||s[i]=='/'){
			sta[sp]=s[i];
			isnum[sp++]=false;
			i++;
		}else {
			int n=0;
			bool minus=false;
			if(s[i]=='-')minus=true,i++;
			while(isdigit(s[i]))n+=n*10+s[i++]-'0';
			if(minus)n=-n;
			int a,b=n;
			if(2<=sp&&!isnum[sp-2]&&sta[sp-1]=='-'){
				sta[sp-1]=-n;
				isnum[sp-1]=true;
			}
			else {
				while(sp&&!isnum[sp-1]&&(sta[sp-1]=='*'|| sta[sp-1]=='/') ){
					char op=sta[--sp];
					a=sta[--sp];
					if(op=='*')b=a*b;
					else b=a/b;
				}
				sta[sp++]=b;			
			}
		}
	}
	int a,b;
	b=sta[--sp];
	while(sp){
		char op=sta[--sp];
		a=sta[--sp];
		if(op=='+')b=a+b;
		else b=a-b;
	}
	return b;
}

int main(){
	int n;
	string s;
	cin>>n;
	while(n--){
		cin>>s;
		cout<<calculator(s)<<endl;
	}
	return 0;
}