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++){
		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]=='/' || str[i-1]=='-')){
			tmp+='-';
		}

		else if(str[i]=='-' && (str[i-1]!='*' && 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));
		}
		break;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef string::const_iterator State;
class ParseError{};

int expr(State& begin);
int term(State& begin);
int number(State& begin);
int fact(State& begin);

int number(State& begin){
    int res = 0;
    while(isdigit(*begin)){
        res *= 10;
        res += *begin - '0';
        begin++;
    }
    return res;
}

int term(State& begin){
    int res = fact(begin);
    while(true){
        if(*begin == '*'){
            begin++;
            res *= fact(begin);
        }else if(*begin == '/'){
            begin++;
            res /= fact(begin);
        }else{
            break;
        }
    }
    return res;
}

int expr(State& begin){
    int res = term(begin);
    while(true){
        if(*begin == '+'){
            begin++;
            res += term(begin);
        }else if(*begin == '-'){
            begin++;
            res -= term(begin);
        }else{
            break;
        }
    }
    return res;
}

int fact(State& begin){
    if(*begin == '('){
        begin++;
        int res = expr(begin);
        begin++;
        return res;
    }
    return number(begin);
}

int main(){
    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        string s;
        cin >> s;
        s = s.substr(0,s.size()-1);
        State begin = s.begin();
        cout << expr(begin) << endl;
    }
}