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 _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <stdio.h>
#include <stdlib.h>

typedef enum{
	INT,
	PLUS,
	MINUS,
	MUL,
	DIV,
	EQ,
	LPAREN,
	RPAREN,
	NL
} token_kind_t;

typedef struct token{
	int c;
	token_kind_t kind;
	int ival;
} *token_t;

int calc_expr_add(token_t t);

token_t next_tok(token_t t)
{
	while (t->c == ' ' || t->c == '\n') {
		t->c = getchar();
	}
	if (isdigit(t->c)){
		t->ival = 0;
		t->kind = INT;
		while (isdigit(t->c)){
			t->ival *= 10;
			t->ival += t->c - '0';
			t->c = getchar();
		}
	}
	else{
		if (t->c == '+') t->kind = PLUS;
		else if (t->c == '-') t->kind = MINUS;
		else if (t->c == '*') t->kind = MUL;
		else if (t->c == '/') t->kind = DIV;
		else if (t->c == '(') t->kind = LPAREN;
		else if (t->c == ')') t->kind = RPAREN;
		else if (t->c == '=') t->kind = EQ;
		else if (t->c == '\n') t->kind = NL;
		else exit(1);

		t->c = getchar();
	}

	return t;
}

token_t mk_tok()
{
	token_t t;
	if ((t = (token_t)malloc(sizeof(struct token))) == NULL){
		perror("malloc");
		exit(1);
	}

	t->c = getchar();

	return t;
}

int calc_expr_un(token_t t)
{
	int ret = 0;
	if (t->kind == INT){
		ret = t->ival;
		next_tok(t);
	}
	else if (t->kind == LPAREN){
		next_tok(t);
		ret = calc_expr_add(t);
		if (t->kind != RPAREN) exit(1);
		next_tok(t);
	}
	else if (t->kind == PLUS || t->kind == MINUS){
		if (t->kind == PLUS){
			next_tok(t);
			ret += calc_expr_un(t);
		}
		else {
			next_tok(t);
			ret -= calc_expr_un(t);
		}
	}
	else exit(1);
	return ret;
}

int calc_expr_mul(token_t t)
{
	int ret = 0;
	ret = calc_expr_un(t);
	while (t->kind == MUL || t->kind == DIV){
		if (t->kind == MUL){
			next_tok(t);
			ret *= calc_expr_un(t);
		}
		else {
			next_tok(t);
			ret /= calc_expr_un(t);
		}
	}
	return ret;
}

int calc_expr_add(token_t t)
{
	int ret = 0;
	ret = calc_expr_mul(t);
	while (t->kind == PLUS || t->kind == MINUS){
		if (t->kind == PLUS){
			next_tok(t);
			ret += calc_expr_mul(t);
		}
		else {
			next_tok(t);
			ret -= calc_expr_mul(t);
		}
	}
	return ret;
}

int calc_expr(token_t t)
{
	int ret = 0;

	next_tok(t);
	ret = calc_expr_add(t);
	if (t->kind != EQ) exit(1);

	return ret;
}

int main()
{
	int n;

	n = getchar() - '0';
	getchar();

	token_t t = mk_tok();

	int i;
	for (i = 0; i < n; i++){
		int result = calc_expr(t);
		printf("%d\n", result);
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// 空白を含む場合の文字列の受け取りはgetline(cin,s)
// cinとgetlineを同時に使う場合はcinの後にcin.ignore()で空白や改行をスキップしてからgetlineしないと空白を受け取ってしまう

typedef string::const_iterator S;
int n;
string s;

int number(S &i), term(S &i), expr(S &i), fact(S &i);

// 数字のパース
int number(S &i) {
	int ret = 0;
	while (isdigit(*i)) {
		ret *= 10;
		ret += *i-'0';
		i++;
	}
	return ret;
}

// 掛け算割り算(または数字単体)のパース
int term(S &i) {
	int ret = fact(i);
	while (1) {
		if (*i=='*') i++, ret *= fact(i);
		else if (*i=='/') i++, ret /= fact(i);
		else break;
	}
	return ret;
}

// termの足し算引き算のパース
int expr(S &i) {
	int ret = term(i);
	while (1) {
		if (*i=='+') i++, ret += term(i);
		else if (*i=='-') i++, ret -= term(i);
		else break;
	}
	return ret;
}

// かっこ付きの式のパース
int fact(S &i) {
	int ret = 0;
	if (*i=='(') {
		i++;
		ret = expr(i);
		i++;
	} else ret = number(i);
	return ret;
}

signed main() {
	cin >> n;
	while (n--) {
		cin >> s;
		S beg = s.begin();
		cout << expr(beg) << ln;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

class Calc{
private:
  int idx;
  string s;
public:
  Calc(string s) : s(s) {
    idx = 0;
  }
  int fact(){
    int res = 0;
    if(s[idx] == '('){
      idx++;
      res = exp();
      idx++;
    }else{
      while(isdigit(s[idx])){
        res *= 10;
        res += s[idx++]-'0';
      }
    }
    return res;
  }

  int term(){
    int res = fact();
    while(s[idx] == '*' || s[idx] == '/'){
      if(s[idx] == '*'){
        idx++;
        res *= fact();
      }else{
        idx++;
        res /= fact();
      }
    }
    return res;
  }

  int exp(){
    int res = term();
    while(s[idx] == '+' || s[idx] == '-'){
      if(s[idx] == '+'){
        idx++;
        res += term();
      }else{
        idx++;
        res -= term();
      }
    }
    return res;
  }

};

int main(){
  int Tc;
  string s;
  cin >> Tc;
  while(Tc--){
    cin >> s;
    s.resize(s.size()-1);
    Calc c(s);
    cout << c.exp() << endl;
  }
  return 0;
}