#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>

void erase(std::vector<std::string>&v,int e,int f){
	for(int i=e;i<v.size()-f;i++)v[i]=v[i+f];
}

std::string solve(std::string str){
	std::vector<std::string>v;
	int a,b,c,d,v_size,j=0;
	for(int i=0;i<=str.size();i++){
		if(i==str.size()||str[i]=='+'||str[i]=='-'||str[i]=='*'||str[i]=='/'){
			v.push_back(str.substr(j,i-j));
			v.push_back(str.substr(i,1));
			j=i+1;
		}
	}
	v_size=v.size();
	a=std::find(v.begin(),v.begin()+v_size,"*")-v.begin();
	while(a!=v_size){
		int p=std::stoi(v[a-1]),q=std::stoi(v[a+1]);
		std::stringstream z;
		z<<p*q;z>>v[a-1];
		erase(v,a,2);v_size-=2;
		a=std::find(v.begin(),v.begin()+v_size,"*")-v.begin();
	}
	b=std::find(v.begin(),v.begin()+v_size,"/")-v.begin();
	while(b!=v_size){
		int p=std::stoi(v[b-1]),q=std::stoi(v[b+1]);
		std::stringstream z;
		z<<p/q;z>>v[b-1];
		erase(v,b,2);v_size-=2;
		b=std::find(v.begin(),v.begin()+v_size,"/")-v.begin();
	}
	c=std::find(v.begin(),v.begin()+v_size,"+")-v.begin();
	while(c!=v_size){
		int p=std::stoi(v[c-1]),q=std::stoi(v[c+1]);
		std::stringstream z;
		z<<p+q;z>>v[c-1];
		erase(v,c,2);v_size-=2;
		c=std::find(v.begin(),v.begin()+v_size,"+")-v.begin();
	}
	d=std::find(v.begin(),v.begin()+v_size,"-")-v.begin();
	while(d!=v_size){
		int p=std::stoi(v[d-1]),q=std::stoi(v[d+1]);
		std::stringstream z;
		z<<p-q;z>>v[d-1];
		erase(v,d,2);v_size-=2;
		d=std::find(v.begin(),v.begin()+v_size,"-")-v.begin();
	}
	return v[0];
}

int main(){
	int n;
	std::string str;
	std::cin>>n;
	for(int i=0;i<n;i++){
		std::cin>>str;
		int a=str.find('('),b=str.find(')');
		while(a!=-1){
			std::string astr=str.substr(a+1,(b-1)-a);
			str.erase(a,b-a+1);
			str.insert(a,solve(astr));
			a=str.find('('),b=str.find(')');
		}
		std::cout<<solve(str.substr(0,str.size()-1))<<std::endl;
	}
	return 0;
}