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 <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);
				goto next;
			}
			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);
				goto next;
			}
		}
		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;
	string s;
	cin >> sets;
	REP(set, sets)
	{
		cin >> s;
		s.erase(s.size() - 1);
		cout << solve(s) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;

int p;
string str;

int Term();
int Factor();
int Elem();
int Digit();

int Term() {
  int a = Factor();
  while (str[p] == '+' || str[p] == '-') {
    char c = str[p];
    p++; // read [+-]
    int b = Factor();
    if (c == '+') {
      a = a + b;
    } else {
      a = a - b;
    }
  }
  return a;
}

int Factor() {
  int a = Elem();
  while (str[p] == '*' || str[p] == '/') {
    char c = str[p];
    p++; // read [*/]
    int b = Elem();
    if (c == '*') {
      a = a * b;
    } else {
      a = a / b;
    }
  }
  return a;
}

int Elem() {
  if (str[p] == '(') {
    p++; // read (
    int a = Term();
    p++; // read )
    return a;
  } else {
    int a = 0;
    while (isdigit(str[p])) {
      int b = Digit();
      a = 10 * a + b;
    }
    return a;
  }
}

int Digit() {
  int a = str[p] - '0';
  p++; // read [0-9]
  return a;
};

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> str;
    p = 0;
    cout << Term() << endl;
  }
}

C++: #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define fst first
string s;
int id;

bool left(){
  return id < (int)s.size()-1;
}
char peek(){
  return s[id];
}
char pop(){
  return s[id++];
}
void eat(char c){
  assert(s[id] == c);
  id++;
}
int expr();
int number(){
  int res = 0;
  while (left() && isdigit(peek())) {
    res = res * 10 + pop() - '0';
  }
  return res;
}
int fact(){
  int res;
  if (isdigit(peek())) {
    return res = number();
  } else {
    eat('(');
    res = expr();
    eat(')');
    return res;
  }
}
int term(){
  int res = fact();
  while (left() && (peek() == '*' || peek() == '/')) {
    if (peek() == '*') {
      eat('*');
      res *= fact();
    } else {
      eat('/');
      res /= fact();
    }
  }
  return res;
}
int expr(){
  int res = term();
  while (left() && (peek() == '+' || peek() == '-')) {
    if (peek() == '+') {
      eat('+');
      res += term();
    } else {
      eat('-');
      res -= term();
    }
  }
  return res;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  REP(i,n){
    id = 0;
    cin >> s;
    cout << expr() << endl;
  }
  return 0;
}