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 <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

typedef pair<ll,const char*> parsed;

parsed expr(const char*);
parsed term(const char*);
parsed fact(const char*);

parsed expr(const char* s)
{
	//cout<<"expr(\""<<s<<"\")"<<endl;
	parsed now=term(s);
	while(*now.second=='+' || *now.second=='-'){
		char op=*now.second;
		parsed next=term(now.second+1);
		if(op=='+')
			now=parsed(now.first+next.first,next.second);
		else
			now=parsed(now.first-next.first,next.second);
	}
	//cout<<"expr(\""<<s<<"\")="<<now.first<<endl;
	return now;
}

parsed term(const char* s)
{
	//cout<<"term(\""<<s<<"\")"<<endl;
	parsed now=fact(s);
	while(*now.second=='*' || *now.second=='/'){
		char op=*now.second;
		parsed next=fact(now.second+1);
		if(op=='*')
			now=parsed(now.first*next.first,next.second);
		else
			now=parsed(now.first/next.first,next.second);
	}
	//cout<<"term(\""<<s<<"\")="<<now.first<<endl;
	return now;
}

parsed fact(const char* s)
{
	//cout<<"fact(\""<<s<<"\")"<<endl;
	//if(s[0]=='('){
	//	parsed res=expr(s+1);
	//	res.second++;
	//	return res;
	//}
	//else{
	//	const char* p=s;
	//	if(*p=='-')
	//		p++;
	//	ll n=0;
	//	while(isdigit(*p)){
	//		n=n*10+*p-'0';
	//		p++;
	//	}
	//	return parsed(n,p);
	//}
	
	if(isdigit(s[0])){
		const char* p=s;
		//if(*p=='-')
		//	p++;
		ll n=0;
		while(isdigit(*p)){
			n=n*10+*p-'0';
			p++;
		}
		return parsed(n,p);
	}
	else{
		parsed res=expr(s+1);
		res.second++;
		return res;
	}
}

//parsed fact(const char *p)
//{
//  if (isdigit(*p)){
//    int t=0;
//    while(isdigit(*p)) t=t*10+*(p++)-'0';
//    return parsed(t,p);
//  }
//  else if (*p=='('){
//    parsed r=expr(p+1);
//    if (*r.second!=')') exit(0); // invalid input
//    return parsed(r.first,r.second+1);
//  }
//  else
//    exit(0); // invalid input
//}

int main()
{
	string s;
	getline(cin,s);
	while(getline(cin,s))
		cout<<expr(s.c_str()).first<<endl;
	
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cctype>

using namespace std;

int number(const string &s, int &k);
int fact(const string &s, int &k);
int term(const string &s, int &k);

int expr(const string &s, int &k){
  int result = term(s,k);
  while(k < s.size()-1){
    if(s[k]=='+')result += term(s,++k);
    else if(s[k]=='-')result -= term(s,++k);
    else return result;
  }
  return result;
}

int term(const string &s, int &k){
  int res = fact(s,k);
  while(k<s.size()-1){
    if(s[k]=='*')return res *= fact(s,++k);
    else if(s[k]=='/')return res /= fact(s,++k);
    else return res;
  }
  return res;
}

int fact(const string &s, int &k){
  if(s[k]=='('){
    int res = 0;
    ++k;
    res = expr(s,k);
    k++;
    return res;
  }
  return number(s,k);
}

int number(const string &s, int &k){
  int res = 0;
  while(isdigit(s[k])){
    res *= 10;
    res += (int)(s[k++] - '0');
  }
  return res;
}

int main(void){

  int n;
  cin >> n;

  while(n--){
    string s;
    cin >> s;
    int k = 0;
    cout << expr(s, k) << endl;
  }
  
  return 0;
}

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

typedef string::const_iterator Iter;

int expr(Iter &p);
int term(Iter &p);
int factor(Iter &p);
int number(Iter &p);

int expr(Iter &p) {
	int r = term(p);
	for(;;)  {
		if(*p == '+') {
			p++;
			int rs = term(p);
			r += rs;
		}
		else if(*p == '-') {
			p++;
			int rs = term(p);
			r -= rs;
		}
		else
			break;
	}
	return r;
}

int term(Iter &p) {
	int r = factor(p);
	for(;;) {
		if(*p == '*') {
			p++;
			int rs = factor(p);
			r *= rs;
		}
		else if(*p == '/') {
			p++;
			int rs = factor(p);
			r /= rs;
		}
		else
			break;
	}
	return r;
}

int factor(Iter &p) {
	if(*p == '(') {
		p++;
		int r = expr(p);
		p++;
		return r;
	}
	else
		return number(p);
}

int number(Iter &p) {
	int r = 0;
	while(isdigit(*p)) {
		r *= 10;
		r += *p - '0';
		p++;
	}
	return r;
}

int main() {
	string line;
	getline(cin, line);
	line = line += "|";
	Iter begin = line.begin();
	cout << expr(begin) << endl;
}

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

long calc2(char *eq){
	long c=0,num[100]={0}, sign[100]={0};
	char *p = eq;
	while(*p){
		if('0'<=*p && *p<='9') num[c]=num[c]*10+*p-'0';
		else{
			if(*p=='+') sign[c]=1;
			else if(*p=='-') sign[c]=2;
			else if(*p=='*') sign[c]=3;
			else if(*p=='/') sign[c]=4;
			else if(*p=='=') break;
			else printf("err %c\n", *p);
			c++;
		}
		p++;
	}
	c++;
	for(long i=0;i<c;i++){
		if(sign[i]==3 || sign[i]==4){
			if(sign[i]==3)	num[i+1] = num[i] * num[i+1];
			if(sign[i]==4)	num[i+1] = num[i] / num[i+1];
			for(long j=i+1;j<c;j++){
				num[j-1] = num[j];
				sign[j-1] = sign[j];
			}
			i--;
			c--;
		}
	}
	for(long i=0;i<c;i++){
		if(sign[i]==1 || sign[i]==2){
			if(sign[i]==1)	num[i+1] = num[i] + num[i+1];
			if(sign[i]==2)	num[i+1] = num[i] - num[i+1];
			for(long j=i+1;j<c;j++){
				num[j-1] = num[j];
				sign[j-1] = sign[j];
			}
			i--;
			c--;
		}
	}
	return num[0];
}

long calc(char *eq){
	char *p, *p2, buf[120]={0}, cp[120]={0};
	long k,ret;
	strcpy(cp, eq);
	if((p=strchr(cp, '('))!=NULL){
		for(k=0,p2=p+1;;p2++)
			if(*p2=='(')k++;
			else if(*p2==')'){
				if(k)k--;
				else break;
			}
		memcpy(buf, p+1, p2-p-1);
		buf[p2-p-1]='=';
		ret = calc(buf);
		*p=0;
		sprintf(buf, "%s%ld%s", cp, ret, p2+1);
		strcpy(cp,buf);
	}
	return calc2(cp);
}

long main(){
	long i,j,n;
	char buf[120], p;
	for(cin >> n;n;n--){
		cin >> buf;
		cout << calc(buf) <<endl;
	}
	return 0;
}