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 <string>
#include <algorithm>
#include <stack>
#include <vector>
#include <stdio.h>

using namespace std;

int getPriority(char ch){
  switch(ch){
  case '+':
    return 0;
  case '-':
    return 1;
  case '/':
    return 2;
  case '*':
    return 3;
  default:
    return -1;
  }
}

vector<string> toReversePorland(string str){

  vector<string> hand;
  vector<string> side;
  
  for(int i = 0; i < str.size(); i++){
    if(str[i] == ' ')
      continue;
    else if(str[i] == '=')
      break;
    if(str[i] >= '0' && str[i] <= '9'){
      string num;
      while(i < str.size()){
	if(str[i] < '0' || str[i] > '9'){
	  break;
	}
	num += str[i];
	i++;
      }
      hand.push_back(num);
      i--;
    }
    else if(str[i] == '('){
      string tmp;
      tmp += str[i];
      side.push_back(tmp);
    }
    else if(str[i] == ')'){
      // ツ右ツ環古環づ慊づ可可算ツ子ツづーツ暗ェツづつつクツづつ偲ィツ個ウツづ可姪淞つキ
      for(int j = side.size()-1 ; ;j--){
	if(side[j] == "("){
	  if(j != 0){
	    vector<string> tmp;
	    for(int k = 0; k < j; k++){
	      tmp.push_back(side[k]);
	    }
	    side = tmp;
	  }
	  else
	    side.clear();
	  break;
	}
	else{
	  string tmp = side[j];
	  hand.push_back(tmp);
	}
      }
    }
    else{
      if(side.size() == 0){
	string tmp;
	tmp += str[i];
	side.push_back(tmp);
      }
      else{
	char cs = side[side.size()-1][0];
	if((cs == '*' || cs == '/') && (str[i] == '*' || str[i] == '/')){
	  hand.push_back(side[side.size()-1]);
	  string tmp;
	  tmp += str[i];
	  side[side.size()-1] = tmp;
	}
	else if(cs != '+' && cs != '-' && cs != '*' && cs != '/'){
	  string tmp;
	  tmp += str[i];
	  side.push_back(tmp);
	}
	else{
	  if(getPriority(str[i]) < getPriority(cs)){
	    hand.push_back(side[side.size()-1]);
	    string tmp;
	    tmp += str[i];
	    side[side.size()-1] = tmp;
	  }
	  else{
	    string tmp;
	    tmp += str[i];
	    side.push_back(tmp);
	  }
	}
      }
    }
  }

  for(int i = side.size()-1; i >= 0; i--){
    string tmp;
    hand.push_back(side[i]);
  }
  for(int i = 0; i < hand.size(); i++)
    cout << hand[i] << flush;
  cout << endl;

  return hand;
}


long long calc(vector<string> str){
  stack<long long> st;
  for(int i = 0; i < str.size(); i++){
    if(str[i] == "+" || str[i] == "-" || str[i] == "*" || str[i] == "/"){
      long long val[2];
      val[0] = st.top();
      st.pop();
      val[1] = st.top();
      st.pop();
      if(str[i] == "+"){
	st.push(val[0] + val[1]);
      }
      if(str[i] == "-"){
	st.push(val[1] - val[0]);
      }
      if(str[i] == "*"){
	st.push(val[0] * val[1]);
      }
      if(str[i] == "/"){
	st.push(val[1] / val[0]);
      }
    }
    else{
      st.push(atoi(str[i].c_str()));
    }
  }
  return st.top();
}

int main(){

  int n;
  string s;
  cin >> n;
  
  vector<string> input;
  string str;
  for(int i = 0; i < n; i++){
    cin >> str;
    input.push_back(str);
  }

  for(int i = 0; i < n; i++){
    str = input[i];
    // vector<string> vec = toReversePorland(str);
    // for(int i = 0; i < vec.size(); i++)
    //   cout << vec[i] << endl;
    cout << calc(toReversePorland(str)) << endl;
  }
  
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
typedef string::const_iterator State;
Def expr(State &i);
Def term(State &i);
Def factor(State &i);
Def number(State &i);
void consume(State &i,char expected){
	if(*i==expected)i++;
	else{
		exit(0);
	}
}
Def expr(State &i){
	Def out=term(i);
	while(*i=='+'||*i=='-'){
		char op=*i;
		i++;
		Def out1=term(i);
		if(op=='+')out+=out1;
		else out-=out1;
	}
	return out;
}
Def term(State &i){
	Def out=factor(i);
	while(*i=='*'||*i=='/'){
		char op=*i;
		i++;
		Def out1=factor(i);
		if(op=='*')out*=out1;
		else out/=out1;
	}
	return out;
}
Def factor(State &i){
	if(isdigit(*i))return number(i);
	//'('
	i++;
	Def out=expr(i);
	i++;
	return out;
}
Def number(State &i){
	Def out=0;
	while(isdigit(*i))out=out*10+*(i++)-'0';
	return out;
}
int main(){
	int n;
	cin>>n;
	while(n--){
		string s;
		cin>>s;
		cout<<expr(s.begin())<<endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <cstdlib>
#include <sstream>
using namespace std;

string str,t;

string calc(string s){

	vector<char> otr;
	otr.reserve(1000);
	vector<int> ond;
	ond.reserve(1000);
	string tmp;
	size_t now = 0;
	
	while( ~s.find_first_of("*/-+=",now) ){
		tmp = s.substr(now,s.find_first_of("*/-+=",now)-now);
		ond.push_back( atoi(tmp.c_str() ) );
		otr.push_back( s[s.find_first_of("*/-+=",now)] );
		now = s.find_first_of("*/-+=",now)+1;
	}

	for(int i=0;i<otr.size();i++){
		if(otr[i]=='*'){
			ond[i] = ond[i] * ond[i+1] ;
			ond.erase(ond.begin()+i+1) ;
			otr.erase(otr.begin()+i)   ;
			i--;
		}else if(otr[i]=='/'){
			ond[i] = ond[i] / ond[i+1] ;
			ond.erase(ond.begin()+i+1) ;
			otr.erase(otr.begin()+i)   ;
			i--;
		}
	}

	/*cout << ond[0];
	for(int j=0;j<otr.size();j++){
		if(otr[j]=='=')break;
		cout << " " << otr[j] << " ";
		cout << ond[j+1];
	}
	cout << endl;
	*/
	for(int i=0;i<otr.size();i++){
		if(otr[i]=='+'){
			ond[i] = ond[i] + ond[i+1] ;
			ond.erase(ond.begin()+i+1) ;
			otr.erase(otr.begin()+i)   ;
		}else if(otr[i]=='-'){
			ond[i] = ond[i] - ond[i+1] ;
			ond.erase(ond.begin()+i+1) ;
			otr.erase(otr.begin()+i)   ;
		}
	}
	stringstream ret;
	if(otr[0]=='+')ret << ond[0]+ond[1];
	else if(otr[0]=='-')ret << ond[0]-ond[1];
	else if(otr[0]=='*')ret << ond[0]*ond[1];
	else if(otr[0]=='/')ret << ond[0]/ond[1];
	else ret << ond[0];
	return ret.str();
}

string parent(string s){	
	int st,en;
	if(~s.find("(")){
			st = s.find("(");
			en = s.rfind(")");
			t = s.substr(st+1,en-st-1);
			s.replace( st , en-st+1 , parent(t+string("=")) );
	}
	return calc(s);
}

int main(){
	int n;
	cin >> n;
	while(cin >> str){
		/*
		if(~s.find("(")){
			st = s.find("(");
			en = s.rfind(")");
			t = s.substr(st+1,en-st-1);
		}*/
		cout << parent(str) << endl;
	}
}