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

/*
   <??????????????????> ::= <??????????????????> (+ or -) <??????????????????> (+ or -) ...
   <??????????????????> ::= <??°> (* or /) <??°> (* or /) ...
   <??°>           ::= ...
   */


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

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


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);
  for(;;) {
    if(*begin == '+') {
        begin++;
        ret += term(begin);
    } else if (*begin == '-')
       {
          begin++;
          ret -= term(begin);
       }
    else{
        break;
    }
    
  }
  return ret;
}
int term(State &begin)
{
  int ret = number(begin);
  for(;;)
  {
    if(*begin == '*')
    {
      begin++;
      ret *= factor(begin);
    } else if(*begin == '/') {
      begin++;
      ret /= factor(begin);
    } else {
      break;
    }
  }
  return ret;
}
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 atoi(string s);
int calc(string in);

int main() {
	int n; cin >> n;
	for (int lop = 0; lop<n; lop++) {
		string in; cin >> in;
		cout << calc(in.substr(0, in.size() - 1)) << endl;
	}
}

int calc(string in) {
	//cout<<in<<endl;
	bool f = true;
	for (int i = 1; i<in.size(); i++) {
		if (in[i]<'0' || '9'<in[i]) {
			f = false;
			break;
		}
	}
	if (f) {
		if (in[0] == '-')
			return -atoi(in.substr(1, in.size() - 1));
		if (in[0] == '+')
			return atoi(in.substr(1, in.size() - 1));
		return atoi(in);
	}
	for (int i = 0; i<in.size(); i++) {
		if (in[i] == '+' || in[i] == '-' || in[i] == '(' || in[i] == ')') {
			f = true;
			break;
		}
	}
	if (!f) {
		int num = 1, start = 0;
		// if op * , else /
		bool op = true;
		for (int i = 0; i<in.size(); i++) {
			if (in[i] == '*' || in[i] == '/') {
				if (op)
					num *= atoi(in.substr(start, i - start));
				else
					num /= atoi(in.substr(start, i - start));
				start = i + 1;
				if (in[i] == '*')
					op = true;
				else
					op = false;
			}
			if (i == in.size() - 1) {
				if (op)
					num *= atoi(in.substr(start, 1 + i - start));
				else
					num /= atoi(in.substr(start, 1 + i - start));
				break;
			}
		}
		return num;
	}
	for (int i = 0; i<in.size(); i++) {
		if (in[i] == '(' || in[i] == ')') {
			f = false;
			break;
		}
	}
	if (f) {
		int start = 0, num = 0;
		// if op + , else - 
		bool op = true;
		for (int i = 0; i<in.size(); i++) {
			if (in[i] == '+' || in[i] == '-') {
				if (op)
					num += calc(in.substr(start, i - start));
				else
					num -= calc(in.substr(start, i - start));
				start = i + 1;
				if (in[i] == '+')
					op = true;
				else
					op = false;
			}
			if (i == in.size() - 1) {
				if (op)
					num += calc(in.substr(start, 1 + i - start));
				else
					num -= calc(in.substr(start, 1 + i - start));
				break;
			}
		}
		return num;
	}
	int level = 1;
	//cout<<in<<endl;
	if (in[0] != '(' || in[in.size() - 1] != ')')
		f = true;
	if (!f) {
		for (int i = 1; i < in.size() - 1; i++) {
			if (in[i] == '(')
				level++;
			if (in[i] == ')')
				level--;
			if (level == 0) {
				f = true;
				break;
			}
		}
		if (!f)
			return calc(in.substr(1, in.size() - 2));
	}
	level = 0;
	for (int i = 0; i<in.size(); i++) {
		if (in[i] == '(') {
			level++;
			continue;
		}
		if (in[i] == ')') {
			level--;
			continue;
		}
		if (level == 0 && (in[i] == '+' || in[i] == '-'))
			f = false;
	}
	if (f) {
		//cout<<in<<endl;
		level = 0;
		int start = 0;
		int num = 1;
		bool op = true;
		for (int i = 0; i<in.size(); i++) {
			if (i == in.size() - 1) {
				if (op)
					num *= calc(in.substr(start, 1 + i - start));
				else
					num /= calc(in.substr(start, 1 + i - start));
			}
			if (in[i] == '(') {
				level++;
				continue;
			}
			if (in[i] == ')') {
				level--;
				continue;
			}
			if (level == 0 && (in[i] == '*' || in[i] == '/')) {
				if (op)
					num *= calc(in.substr(start, i - start));
				else
					num /= calc(in.substr(start, i - start));
				start = i + 1;
				if (in[i] == '*')
					op = true;
				else
					op = false;
			}
		}
		return num;
	}
	int start = 0, num = 0;
	level = 0;
	bool op = true;
	for (int i = 0; i<in.size(); i++) {
		if (i == in.size() - 1) {
			if (op)
				num += calc(in.substr(start, 1 + i - start));
			else
				num -= calc(in.substr(start, 1 + i - start));
		}
		if (in[i] == '(') {
			level++;
			continue;
		}
		if (in[i] == ')') {
			level--;
			continue;
		}
		if (level == 0 && (in[i] == '+' || in[i] == '-')) {
			if (op)
				num += calc(in.substr(start, i - start));
			else
				num -= calc(in.substr(start, i - start));
			start = i + 1;
			if (in[i] == '+')
				op = true;
			else
				op = false;
		}
	}
	return num;
}

int atoi(string s) {
	int n = 0;
	for (int i = 0; i<s.size(); i++) {
		n = n * 10 + s[i] - '0';
	}
	return n;
}

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

void select_cal(char c, int *tmp, int val){

	if(c == '+') *tmp += val;
	else if(c == '-') *tmp -= val;
	else if(c == '*') *tmp = floor(*tmp * val);
	else if(c == '/' && val != 0) *tmp = floor(*tmp / val);

}

int calculation(string str, int len, int begin){

	int ans, tmp, cnt, val;
	char c;
	
	ans = 0;
	tmp = 0;
	c = '+';

	for(int i=begin; i<len; i++){
		if(str[i] == '+' || str[i] == '-'){
			ans += tmp;
			tmp = 0;
			c = str[i];
		}
		else if(str[i] == '*' || str[i] == '/'){
			c = str[i];
		}
		else if(str[i] == '('){
			select_cal(c, &tmp, calculation(str, len, i+1));
			cnt = 1;
			do{
				i++;
				if(str[i] == '(') cnt++;
				else if(str[i] == ')') cnt--;
			}while(cnt != 0);
		}
		else if(str[i] == ')' || str[i] == '='){
			break;
		}
		else {
			cnt = 1;
			while(str[i+cnt] >= '0' && str[i+cnt] <= '9'){
				cnt++;
			}
			val = 0;
			for(int j=0; j<cnt; j++){
				val += (str[i+cnt-j-1] - '0') * pow(10, j);
			}
			select_cal(c, &tmp, val);
			i += cnt - 1;
		}
	}
	ans += tmp;

	return ans;

}

int main(){

	int n;
	string str;
	
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> str;
		cout << calculation(str, str.length(), 0) << endl;
	}

	return 0;

}