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<cctype>
#include<string>
using namespace std;
typedef string::const_iterator State;

int expression(State &);
int term(State &);
int factor(State &);
int number(State &);

int main(void){
  int N;
  cin >> N;
  cin.ignore();
  
  for(int i=0;i<N;i++){
    string s;
    getline(cin,s);

    State begin=s.begin();
    int ans=expression(begin);
    cout << ans << endl;
  }
  return 0;
}

int expression(State &begin){
  int ret=term(begin);
  
  while(1){
    if(*begin=='+'){
      begin++;
      ret+=term(begin);
    }
    else if(*begin=='-'){
      begin++;
      ret-=term(begin);
    }
    else break;
  }
  return ret;
}

int term(State &begin){
  int ret=factor(begin);
  
  while(1){
    if(*begin=='*'){
      begin++;
      ret*=factor(begin);
    }
    else if(*begin=='/'){
      begin++;
      ret/=factor(begin);
    }
    else break;
  }
  return ret;
}

int factor(State &begin){
  if(*begin=='('){
    begin++;
    int ret=expression(begin);
    begin++;
    return ret;
  }
  if(*begin=='-'){
    begin++;
    return -factor(begin);
  }
  return number(begin);
}

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

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

int k,n,ans;
string s;

int calc1();
int calc2();
int calc3();

int calc1(){
	int a;
	a=calc2();
	while(s[k]=='+' ||s[k]=='-'){
		if(s[k]=='+'){
			k++;
			a+=calc2();
		}else if(s[k]=='-'){
			k++;
			a-=calc2();
		}
	}
	return a;
}

int calc2(){
	int a;
	a=calc3();
	while(s[k]=='*' ||s[k]=='/'){
		if(s[k]=='*'){
			k++;
			a*=calc3();
		}else if(s[k]=='/'){
			k++;
			a/=calc3();
		}
	}
	return a;
}

int calc3(){
	int a;
	if(s[k]=='('){
		k++;
		a=calc1();
		k++;
	}else{
		a=0;
		while(s[k]>='0' && s[k]<='9'){
			a*=10;
			a+=s[k]-'0';
			k++;
		}
	}
	return a;
}

int main(){
	cin >> n;
	while(n--){
		ans=0;
		int k=0;
		cin >> s;
		ans=calc1();
		cout << ans <<endl;
	}
	return 0;
}

C++: using namespace std;
string its(int n){
  stringstream s;
  s<<n;
  return s.str();
}
stack<string> mep(stack<string> me,string s){
  int a,b;
  b=atoi(me.top().c_str());
  me.pop();
  a=atoi(me.top().c_str());
  me.pop();
  if(s=="+")
    me.push(its(a+b));
  else if(s=="-")
    me.push(its(a-b));
  else if(s=="*")
    me.push(its(a*b));
  else if(s=="/")
    me.push(its(a/b));
  return me;
}
int main(){
  int h,i,j;
  int n,len;
  string s;
  stack<string> me,st;
  cin>>n;
  for(h=0;h<n;h++){
    cin>>s;
    len=s.length()-1;
    for(i=0;i<len;i++){
      if('1'<=s[i]&&s[i]<='9'){
	for(j=i;j<len;j++)
	  if(s[j]<'0'||'9'<s[j])
	    break;	
	me.push(s.substr(i,j-i));
	i=j-1;
      }else if(s[i]=='('){
	st.push(s.substr(i,1));
      }else if(s[i]==')'){
	while(st.top()!="("){
	  me=mep(me,st.top());
	  st.pop();
	}
	st.pop();
      }else if(s[i]=='+'||s[i]=='-'){
	if(st.empty());
	else if(st.top()=="(");
	else{
	  while(st.empty()==0){
	    if(st.top()=="(")
	      break;
	    else{
	      me=mep(me,st.top());
	      st.pop();
	    }
	  }
	}
	st.push(s.substr(i,1));
      }else if(s[i]=='*'||s[i]=='/'){
	if(st.empty());
	else if(st.top()=="(");
	else if(st.top()=="+"||st.top()=="-");
	else{
	  while(st.empty()==0){
	    if(st.top()=="(")
	      break;
	    else if(st.top()=="+"||st.top()=="-")
	      break;
	    else{
	      me=mep(me,st.top());
	      st.pop();
	    }
	  }
	}
	st.push(s.substr(i,1));
      }
    }
    while(st.empty()==0){
      me=mep(me,st.top());
      st.pop();
    }
    cout<<me.top()<<endl;
    me.pop();
  }
  return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

typedef string::const_iterator state;
class parse_error {};

//Debug
//state it_begin, it_end;

void compare(state &it, char expected) {
	if (*it != expected) {
		cerr << "Expected '" << expected << "',";
		cerr << "got '" << *it << "'";

		//Debug
		//cerr << " rest \"";
		//while (it < it_end) {
		//	cerr << *it++;
		//}
		//cerr << "\"";

		cout << endl;
		throw parse_error();
	}
}

/*

EBNF

expression	= {['+'|'-'] term} | '=';
term		= factor {('*'|'/') factor};
factor		= '(' expression ')' | integer;
integer		= digit {digit};
digit		= '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9';

*/

int expression(state &it);
int term(state &it);
int factor(state &it);
int integer(state &it);

int expression(state &it) {
	if (*it == '=')return 0;

	int ret = term(it);

	while (true) {
		if (*it == '+') {
			it++;
			ret += term(it);
		}
		else if (*it == '-') {
			it++;
			ret -= term(it);
		}
		else {
			break;
		}
	}

	return ret;
}

int term(state &it) {
	int ret = factor(it);

	while (true) {
		if (*it == '*') {
			it++;
			ret *= factor(it);
		}
		else if (*it == '/') {
			it++;
			ret /= factor(it);
		}
		else {
			break;
		}
	}
	return ret;
}

int factor(state &it) {
	if (*it == '(') {
		it++;
		int ret = expression(it);
		compare(it, ')');
		it++;
		return ret;
	}
	else {
		return integer(it);
	}
}

int integer(state &it) {
	int ret = 0;

	while (isdigit(*it)) {
		ret *= 10;
		ret += *it - '0';
		it++;
	}

	return ret;
}

int main() {
	int N; cin >> N;
	cin.ignore();
	for (int i = 0; i < N; i++) {
		string s;
		getline(cin, s);

		state it = s.begin();

		//Debug
		//it_begin = s.begin();
		//it_end = s.end();

		int ans = expression(it);
		compare(it, '=');
		cout << ans << endl;
	}
	return 0;
}