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++: #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++){
		if(v[i]=="-"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

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

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

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

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

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

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

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

			string res;
			char buf[64];
			sprintf(buf,"%d",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]=='/'){
			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));
		}
	}
}

C++: #include <iostream>
#include <string>
#include <cctype>
using namespace std;
typedef string::const_iterator State;

int number(State &begin);
int term(State &begin);
int expression(State &begin);
int factor(State &begin);

int number(State &begin) {
	int ret = 0;
	
	while (isdigit(*begin)) {
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}
	// cout << "number :: " << ret << endl;
	return ret;
}
int term(State &begin) {
	int ret = factor(begin);
	
	while(1) {
		if (*begin == '*') {
			begin++;
			// cout << "go factor // *" << endl;
			ret *= factor(begin);
		}
		else if (*begin == '/') {
			begin++;
			// cout << "go factor // /" << endl;
			ret /= factor(begin);
		}
		else break;
	}
	// // cout << "term :: " << ret << endl;
    return ret;
}
int expression(State &begin) {
	int ret = term(begin);
	
	while(1) {
		if (*begin == '+') {
			begin++;
			// // cout << "go term // +" << endl;
			ret += term(begin);
		}
		else if (*begin == '-') {
			begin++;
			// // cout << "go term // -" << endl;
			ret -= term(begin);
        }
        else break;
	}
	// // cout << "expression :: " << ret << endl;
	return ret;
}
int factor(State &begin) {
	if (*begin == '(') {
		begin++; 
		// // cout << "go expression" << endl;
		int ret = expression(begin);
		// // cout << "factor :: " << ret << endl;
		begin++;
		return ret;
	}
	else return number(begin);
}

int main(void) {
	int n;
	cin >> n;
	cin.ignore();
	for (int i = 0; i < n; i++) {
		string s;
		getline(cin, s);
		
		State begin = s.begin();
		 // cout << "Start !!!" << endl;
		cout << expression(begin) << endl;
	}
	return 0;
}