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 <map>
#include <algorithm>
#include <cctype>
using namespace std;

typedef string::const_iterator State;
int n;
string str;

int factor(State &begin);
int number(State &begin);
int term(State &begin);
int expressin(State &begin);

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

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

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

	return ret;
}

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

	return ret;
}


int main()
{
	cin >> n;
	while (n--)
	{
		cin >> str;
		cout << expressin(str.begin()) << endl;
	}

	return 0;
}

C++: #include <string>
#include <cctype>
#include <iostream>
typedef std::string::const_iterator State;
class ParseError {};

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

int main(){
	int N;
	std::cin >> N;
	std::cin.ignore();
	for(int i = 0; i < N; ++i){
		std::string s;
		std::getline(std::cin, s);
		State begin = s.begin();
		int ans = expression(begin);
		std::cout << ans << std::endl;
	}
	return 0;
}

int number(State &begin){
	int ret = 0;

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

	return ret;
}

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

int term(State &begin){
	int ret = factor(begin);

	for(;;){
		if(*begin == '*'){
			begin++;
			ret *= factor(begin);
		}else if(*begin == '/'){
			begin++;
			ret /= factor(begin);
		}else{
			break;
		}
	}
	return ret;
}

int expression(State &begin){
	int ret = term(begin);

	for(;;){
		if(*begin == '+'){
			begin++;
			ret += term(begin);
		} else if(*begin == '-'){
			begin++;
			ret -= term(begin);
		}else {
			break;
		}
	}
	return ret;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

vector<string> split(string delim,string str){
	vector<string> res;
	str += delim;
	for(int i=0;i<str.size();i++){
		for(int j=1;i+j<=str.size();j++){
			if(str.substr(i,j).find_first_of(delim) != string::npos){
				//cout << str.substr(i,j) << endl;
				if(str.substr(i,j-1).size() > 0 ) res.push_back(str.substr(i,j-1));
				i+=j-1;
				break;
			}
		}
	}

	return res;
}

string calc(vector<string> v){
	stack<string> stk;
	for(int i=0;i<v.size();i++){
		if(v[i]=="-"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

			int num1;
			sscanf(str1.c_str(),"%d",&num1);
			
			int num2;
			sscanf(str2.c_str(),"%d",&num2);

			string res;
			char buf[64];
			sprintf(buf,"%d",num2-num1);
			res = buf;
			
			stk.push(res);
		}
		else if(v[i]=="+"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

			int num1;
			sscanf(str1.c_str(),"%d",&num1);
			
			int num2;
			sscanf(str2.c_str(),"%d",&num2);

			string res;
			char buf[64];
			sprintf(buf,"%d",num2+num1);
			res = buf;
			
			stk.push(res);
		}
		else if(v[i]=="*"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

			int num1;
			sscanf(str1.c_str(),"%d",&num1);
			
			int num2;
			sscanf(str2.c_str(),"%d",&num2);

			string res;
			char buf[64];
			sprintf(buf,"%d",num2*num1);
			res = buf;
			
			stk.push(res);
		}
		else if(v[i]=="/"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

			int num1;
			sscanf(str1.c_str(),"%d",&num1);
			
			int num2;
			sscanf(str2.c_str(),"%d",&num2);

			string res;
			char buf[64];
			sprintf(buf,"%d",num2/num1);
			res = buf;
			
			stk.push(res);
		}
		else{
			stk.push(v[i]);
		}
	}
	return stk.top();
}

vector<string> rvs_polish(string str){
	stack<string> stk;
	vector<string> v;

	string tmp="";
	vector<string> res;
	for(int i=0;i<str.size();i++){
		if(str[i]=='*'){
			v.push_back(tmp);
			v.push_back("*");			
			tmp="";
		}
		else if(str[i]=='-'){
			v.push_back(tmp);
			v.push_back("-");			
			tmp="";
		}
		else if(str[i]=='/'){
			v.push_back(tmp);
			v.push_back("/");			
			tmp="";
		}
		else if(str[i]=='+'){
			v.push_back(tmp);
			v.push_back("+");			
			tmp="";
		}
		else if(str[i]=='='){
			v.push_back(tmp);
			v.push_back("=");			
			tmp="";
		}

		else{
			tmp+=str.substr(i,1);
		}
	}

	v.push_back(tmp);

	for(int i=0;i<v.size();i++){
		if(v[i]=="*"){
			if(stk.empty()){
				stk.push("*");
			}
			else{
				string opr = stk.top();
				if(opr == "-" || opr == "+"){
					stk.push("*");
				}
				else{
					while(!stk.empty()){
						res.push_back(stk.top());
						stk.pop();
					}
					stk.push("*");
				}
			}
		}

		else if(v[i]=="/"){
			if(stk.empty()){
				stk.push("/");
			}
			else{
				string opr = stk.top();
				if(opr == "-" || opr == "+" || opr == "*"){
					stk.push("/");
				}
				else{
					while(!stk.empty()){
						res.push_back(stk.top());
						stk.pop();
					}
					stk.push("/");
				}
			}
		}

		else if(v[i]=="-"){
			if(stk.empty()){
				stk.push("-");
			}
			else{
				while(!stk.empty()){
					res.push_back(stk.top());
					stk.pop();
				}
				stk.push("-");
			}
		}
		else if(v[i]=="+"){
			if(stk.empty()){
				stk.push("+");
			}
			else{
				while(!stk.empty()){
					res.push_back(stk.top());
					stk.pop();
				}
				stk.push("+");
			}
		}
		else{
			res.push_back(v[i]);
		}
	}

	while(!stk.empty()){
		res.push_back(stk.top());
		stk.pop();
	}

	return res;
}

string dfs(string str){
	int rc=0,lc=0;
	stack<P> stk;
	string res="";
	for(int i=0;i<str.size();i++){
		if(str[i]=='(') {stk.push(P('(',i));}
		else if(str[i]==')') {
			char sym = stk.top().first;
			if(sym != '(') continue;

			int pos = stk.top().second;
			stk.pop();

			vector<string> pol = rvs_polish(str.substr(pos+1,(i-1)-(pos+1)+1));
			string num = calc(pol);
			res+=num;
		}
		else if(stk.empty() || (!stk.empty() && stk.top().first != '(')){
			res+=str[i];
		}
	}

	return res;
}

int main(){
	string str;
	while(getline(cin,str)){
		int n;
		sscanf(str.c_str(),"%d",&n);
		for(int i=0;i<n;i++){
			getline(cin,str);
			string str1 = dfs(str.substr(0,str.size()-1));
			vector<string> pol = rvs_polish(str1);
			string num = calc(pol);

			cout << num << endl;
		}
	}
}

C++: #!/usr/bin/python3

import re
n = int(input())
for _ in range(n):
    print(eval(re.sub(r'(\d+/\d+)', r'int(\1)', input()[0:-1])))