Go: package main

import (
	"bufio"
	"fmt"
	"go/token"
	"go/types"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		stdin.Scan()
		exp := strings.TrimRight(stdin.Text(), "=")
		res, _ := types.Eval(token.NewFileSet(), nil, token.NoPos, exp)
		fmt.Println(res.Value)
	}
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

typedef pair<int,const char*> parsed;

parsed expr(const char*);
parsed term(const char*);
parsed fact(const char*);

parsed expr(const char* s)
{
	//cout<<"expr(\""<<s<<"\")"<<endl;
	parsed now=term(s);
	while(*now.second!='=' && *now.second!=')'){
		char op=*now.second;
		parsed next=term(now.second+1);
		if(op=='+')
			now=parsed(now.first+next.first,next.second);
		else
			now=parsed(now.first-next.first,next.second);
	}
	//cout<<"expr(\""<<s<<"\")="<<now.first<<endl;
	return now;
}

parsed term(const char* s)
{
	//cout<<"term(\""<<s<<"\")"<<endl;
	parsed now=fact(s);
	while(*now.second!='=' && *now.second!=')' && *now.second!='+' && *now.second!='-'){
		char op=*now.second;
		parsed next=fact(now.second+1);
		if(op=='*')
			now=parsed(now.first*next.first,next.second);
		else
			now=parsed(now.first/next.first,next.second);
	}
	//cout<<"term(\""<<s<<"\")="<<now.first<<endl;
	return now;
}

parsed fact(const char* s)
{
	//cout<<"fact(\""<<s<<"\")"<<endl;
	if(s[0]=='('){
		parsed res=expr(s+1);
		res.second++;
		return res;
	}
	else{
		const char* p=s;
		if(*p=='-')
			p++;
		while(isdigit(*p))
			p++;
		return parsed(atoi(s),p);
	}
}

int main()
{
	//parsed p=expr("((3+4)/(1+2))=");
	//cout<<p.first<<","<<p.second<<endl;
	char s[101];
	gets(s);
	while(gets(s))
		cout<<expr(s).first<<endl;
	
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

vector<string> split(string delim,string str){
	vector<string> res;
	str += delim;
	for(int i=0;i<str.size();i++){
		for(int j=1;i+j<=str.size();j++){
			if(str.substr(i,j).find_first_of(delim) != string::npos){
				//cout << str.substr(i,j) << endl;
				if(str.substr(i,j-1).size() > 0 ) res.push_back(str.substr(i,j-1));
				i+=j-1;
				break;
			}
		}
	}

	return res;
}

string calc(vector<string> v){
	stack<string> stk;
	for(int i=0;i<v.size();i++){
		ll num1;
		ll num2;
		char buf[256];
		string res;
		if(v[i]=="-"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

			sscanf(str1.c_str(),"%lld",&num1);
			sscanf(str2.c_str(),"%lld",&num2);

			sprintf(buf,"%lld",num2-num1);
			res = buf;
			
			stk.push(res);
		}
		else if(v[i]=="+"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

			sscanf(str1.c_str(),"%lld",&num1);
			sscanf(str2.c_str(),"%lld",&num2);

			sprintf(buf,"%lld",num2+num1);
			res = buf;
			
			stk.push(res);
		}
		else if(v[i]=="*"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

			sscanf(str1.c_str(),"%lld",&num1);
			sscanf(str2.c_str(),"%lld",&num2);

			sprintf(buf,"%lld",num2*num1);
			res = buf;
			
			stk.push(res);
		}
		else if(v[i]=="/"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

			sscanf(str1.c_str(),"%lld",&num1);
			sscanf(str2.c_str(),"%lld",&num2);

			sprintf(buf,"%lld",num2/num1);
			res = buf;
			
			stk.push(res);
		}
		else{
			stk.push(v[i]);
		}
	}
	return stk.top();
}

vector<string> rvs_polish(string str){
	stack<string> stk;
	vector<string> v;

	string tmp="";
	vector<string> res;
	if(str[0]=='-'){
		str='0'+str;
	}
	for(int i=0;i<str.size();i++){
		if(str[i]=='*'){
			v.push_back(tmp);
			v.push_back("*");
			tmp="";
		}

		else if(str[i]=='/'){
			v.push_back(tmp);
			v.push_back("/");
			tmp="";
		}

		else if(str[i]=='-' && (str[i-1]=='*' || str[i-1]=='/')){
			tmp+='-';
		}

		else if(str[i]=='-' && (str[i-1]!='*' && str[i-1]!='/')){
			v.push_back(tmp);
			v.push_back("-");			
			tmp="";
		}

		else if(str[i]=='+'){
			v.push_back(tmp);
			v.push_back("+");			
			tmp="";
		}
		else if(str[i]=='='){
			v.push_back(tmp);
			v.push_back("=");			
			tmp="";
		}

		else{
			tmp+=str.substr(i,1);
		}
	}

	v.push_back(tmp);

	for(int i=0;i<v.size();i++){
		if(v[i]=="*"){
			if(stk.empty()){
				stk.push("*");
			}
			else{
				string opr = stk.top();
				if(opr == "-" || opr == "+"){
					stk.push("*");
				}
				else{
					while(!stk.empty()){
						res.push_back(stk.top());
						stk.pop();
					}
					stk.push("*");
				}
			}
		}

		else if(v[i]=="/"){
			if(stk.empty()){
				stk.push("/");
			}
			else{
				string opr = stk.top();
				if(opr == "-" || opr == "+" || opr == "*"){
					stk.push("/");
				}
				else{
					while(!stk.empty()){
						res.push_back(stk.top());
						stk.pop();
					}
					stk.push("/");
				}
			}
		}

		else if(v[i]=="-"){
			if(stk.empty()){
				stk.push("-");
			}
			else{
				while(!stk.empty()){
					res.push_back(stk.top());
					stk.pop();
				}
				stk.push("-");
			}
		}
		else if(v[i]=="+"){
			if(stk.empty()){
				stk.push("+");
			}
			else{
				while(!stk.empty()){
					res.push_back(stk.top());
					stk.pop();
				}
				stk.push("+");
			}
		}
		else{
			res.push_back(v[i]);
		}
	}

	while(!stk.empty()){
		res.push_back(stk.top());
		stk.pop();
	}

	return res;
}

void dfs(string str){
	stack<P> stk;
	for(int i=0;i<str.size();i++){
		if(str[i]=='(') {stk.push(P('(',i));}
		else if(str[i]==')') {
			char sym = stk.top().first;
			if(sym != '(') continue;

			int pos = stk.top().second;
			stk.pop();

			if(str.substr(pos+1,(i-1)-(pos+1)+1).find('(') == string::npos
				&& str.substr(pos+1,(i-1)-(pos+1)+1).find(')') == string::npos){
					vector<string> pol = rvs_polish(str.substr(pos+1,(i-1)-(pos+1)+1));
					string num = calc(pol);
					str.replace(pos,i-pos+1,num);
					//cout << str << endl;
					while(!stk.empty()) stk.pop();
					i=-1;
					continue;
			}
		}
	}

	vector<string> ans = rvs_polish(str);

	cout << calc(ans) << endl;
}

int main(){
	string str;
	while(getline(cin,str)){
		int n;
		sscanf(str.c_str(),"%d",&n);
		for(int i=0;i<n;i++){
			getline(cin,str);
			dfs(str.substr(0,str.size()-1));
		}
	}
}