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 <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>

using namespace std;


int main(){
    int n;
    string s;
    while(cin>>n){
        for(int i=0; i<n; i++){
            cin>>s;
            int j=0;
            
            queue<string> qu;
            stack<string> st;
            
            
            while(j<s.length()){
                //cout<<s[j]<<endl;
                //数値の処理
                if(s[j]>='0'&&s[j]<='9'){
                    string s_temp;
                    
                    while(s[j]>='0'&&s[j]<='9'){
                        s_temp+=s[j];
                        j++;
                    }
                    
                    qu.push(s_temp);
                    
                }
                
                //括弧の処理
                else if(s[j]==')'){
                    while(1){
                        string s_temp;
                        s_temp = st.top();
                        st.pop();
                        if(s_temp=="("){
                            break;
                        }else{
                            qu.push(s_temp);
                        }
                    }
                    j++;
                }
                
                else if(s[j]=='('){
                    string s_temp;
                    s_temp+=s[j];
                    st.push(s_temp);
                    j++;
                }
                
                //演算子の処理
                else if(s[j]=='-'||s[j]=='+'||s[j]=='*'||s[j]=='/'){
                    string s_temp;
                    s_temp+=s[j];
                    if(st.empty()){
                        st.push(s_temp);
                        j++;
                    }else{
                        if(!((s_temp=="*"||s_temp=="/")&&(st.top()=="-"||st.top()=="+"))){
                            s_temp = st.top();
                            st.pop();
                            qu.push(s_temp);
                        }else{
                            st.push(s_temp);
                            j++;
                        }
                    }
                }
                //=の処理
                else if(s[j]=='='){
                    j++;
                }
                
                
            }
            while(!st.empty()){
                qu.push((st.top()));
                st.pop();
            }
            
            stack<int> num;
            while(!qu.empty()){
                
                //cout<<qu.front()<<endl;
                
                if(qu.front()=="*"){
                    int a,b;
                    a=num.top();
                    num.pop();
                    b=num.top();
                    num.pop();
                    a=b*a;
                    num.push(a);
                }else if(qu.front()=="/"){
                    int a,b;
                    a=num.top();
                    num.pop();
                    b=num.top();
                    num.pop();
                    a=b/a;
                    num.push(a);
                    
                }else if(qu.front()=="-"){
                    int a,b;
                    a=num.top();
                    num.pop();
                    b=num.top();
                    num.pop();
                    a=b-a;
                    num.push(a);
                }else if(qu.front()=="+"){
                    int a,b;
                    a=num.top();
                    num.pop();
                    b=num.top();
                    num.pop();
                    a=b+a;
                    num.push(a);
                }else{
                    stringstream stream;
                    stream<<qu.front();
                    int temp;
                    stream>>temp;
                    num.push(temp);
                }
                qu.pop();
            }
            cout<<num.top()<<endl;
        }
        
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int calc(string s)
{
	vi v;
	REP(i, s.size())
	{
		if (s[i] == '+') v.push_back(0);
		else if (s[i] == '-') v.push_back(1);
		else if (s[i] == '*') v.push_back(2);
		else if (s[i] == '/') v.push_back(3);
		else
		{
			int tmp = s[i] - '0';
			int t = i+1;
			while (isdigit(s[t]))
			{
				tmp = tmp * 10 + s[t] - '0';
				t++;
			}
			i = t - 1;
			v.push_back(tmp);
		}
	}

	while (v.size() > 1)
	{
		for (int i = 1; i < v.size();i+=2)
		{
			if (v[i]==2)
			{
				int tmp = v[i - 1] * v[i + 1];
				v[i - 1] = tmp;
				v.erase(v.begin() + i + 1);
				v.erase(v.begin() + i);
				continue;
			}
			else if (v[i] == 3)
			{
				int tmp = v[i - 1] / v[i + 1];
				v[i - 1] = tmp;
				v.erase(v.begin() + i + 1);
				v.erase(v.begin() + i);
				continue;
			}
		}
		for (int i = 1; i < v.size(); i += 2)
		{
			if (v[i] == 0)
			{
				int tmp = v[i - 1] + v[i + 1];
				v[i - 1] = tmp;
				v.erase(v.begin() + i + 1);
				v.erase(v.begin() + i);
				break;
			}
			else if (v[i] == 1)
			{
				int tmp = v[i - 1] - v[i + 1];
				v[i - 1] = tmp;
				v.erase(v.begin() + i + 1);
				v.erase(v.begin() + i);
				break;
			}
		next:;
		}
	}
	return v[0];
}

int solve(string s)
{
	while (1)
	{
		if (find(ALL(s), '(') == s.end())
		{
			return calc(s);
		}
		else
		{
			string tmp;
			REP(i, s.size())
			{
				if (s[i] != '(') tmp.push_back(s[i]);
				else
				{
					int j;
					for (j = s.size()-1;; j--)
					{
						if (s[j] == ')')
						{
							int t = solve(s.substr(i+1, j - i - 1));
							tmp += to_string(t);
							break;
						}
					}
					i = j;
				}
			}
			return solve(tmp);
		}
	}
	return 0;
}

int main()
{
	int sets;
	cin >> sets;
	string s;
	getline(cin, s);
	REP(set, sets)
	{
		getline(cin, s);
		if (s.size() == 0) puts("0");
		else
		{
			s.erase(s.size() - 1);
			cout << solve(s) << endl;
		}
	}
	return 0;
}