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++: #pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define repr(i ,n) for(int i=n;i>(int)(n);--i)
#define rep1(i ,n) for(int i=1;i<=(int)(n);++i)
#define ALL(a) a.begin(), a.end()
#define RSORT(a) sort(ALL(a),greater<>())
#define SORT(a) sort(ALL(a))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define PRINT(x) cout << (x) << endl
#define ENDL printf("\n")
using namespace std;
typedef long long int i64;
typedef unsigned long long u64;
template<class T> using V = vector<T>;
using VI = V<int>;
const int INF = 2e9;
const i64 MOD = 1e9 + 7;
 
template <class T> inline bool chmin(T& a, T b){if(a>b){a=b; return true;} return false;}
template <class T> inline bool chmax(T& a, T b){if(a<b){a=b; return true;} return false;}
struct Init_On{
    Init_On(){
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(16);
    }
};
 
int calc(string& s){
    int num_of_op = 0;
    s.insert(s.begin(),'s');
    int len = s.size();
    string operand;
    operand.clear();
    rep( i , len){
        if((s[i] > '9' || s[i] < '0') && s[i]!='s') {
            if( s[i] == '-' && (s[i-1] >'9' || s[i-1] <'0' && i-1 >=0 )) continue;
            ++num_of_op;
        }
    }
    vector<int> num(num_of_op+1);
    vector<char> op(num_of_op);
    int x = 0;
    rep(i , len){
        if((s[i] > '9' || s[i] < '0') && s[i] != 's'){
            if(s[i] == '-' && (s[i-1] > '9' || s[i-1] < '0' && i-1 >=0)) continue;
            op[x++] = s[i];
        }
    }
    s += 'e';
    int j = 0;
    bool flag = false;
    for( int i = 0 ; i < num_of_op + 1  ; ++i){
        for( ; (s[j] <= '9' && s[j] >= '0') || s[j] == 's' || flag ; ++j){
            if(s[j] =='s' && s[j+1] == '-') { operand += '-'; ++j; continue; }
            if((s[j-1] >'9' || s[j-1] < '0' ) && s[j] == '-' && j-1 >= 0 ) { operand += '-'; flag = true; continue;}
            if(s[j] != 's' && ( s[j]<='9' && s[j]>='0') ) { operand += s[j]; flag = false; }
        }
        num[i] = stoi(operand);
        operand.clear();
        ++j;
        if(s[j]=='-') flag = true;
    }
    int muldiv = 0 , sumdiff = 0;
    rep( i , num_of_op){
        
        if (op[i] == '+' || op[i] == '-') ++sumdiff;
        else if (op[i] == '*' || op[i] == '/') ++muldiv;
    }
    while(muldiv){
        rep( i , num_of_op){
            if(op[i] == '*'){
                num[i+1] = num[i] * num[i+1];
                num.erase(num.begin()+i); op.erase(op.begin()+i); --i; --num_of_op;
                --muldiv;
            } else if(op[i] == '/'){
                num[i+1] = num[i] / num[i+1];
                num.erase(num.begin()+i); op.erase(op.begin()+i); --i; --num_of_op;
                --muldiv;
            }
        }
    }
    while(sumdiff){
        rep(i , num_of_op){
            if( op[i] == '+'){
                { num[i+1] = num[i] + num[i+1]; num.erase(num.begin()+i); op.erase(op.begin()+i); --num_of_op; --i; --sumdiff; }
            }
            else if (op[i] == '-'){
                { num[i+1] = num[i] - num[i+1]; num.erase(num.begin()+i); op.erase(op.begin()+i); --num_of_op; --i; --sumdiff; }
            }
        }

    }
    return num[0];
}
 
signed main(){
    Init_On start;
    int n; cin >> n;
    int t = n;
    VI ans(t);
    while(t){
        string s; cin >> s;
        string tmp;
        auto itr = s.end(); --itr; s.erase(itr);
        int i , j;
        int num_br = 0;
        rep( k , s.size()) {
            if(s[k] == ')') ++num_br;
        }
        if( num_br == 0) { ans.push_back(calc(s)); --t; continue; }
        while(num_br){
            for( i = 0 ; i < s.size() ; ++i){
                if(s[i]==')'){
                    auto itr1 = s.begin();
                    rep( k , i) ++itr1;
                    s.erase(itr1);
                    j = i;
                    for( ; s[j]!='('; --j ){}
                    auto itr2 = s.begin();
                    rep( k , j) ++itr2;
                    s.erase(itr2);
                    break; 
                }
            }
                tmp = s.substr(j , i-j-1);
                tmp = to_string(calc(tmp));
                s.replace( j , i-j-1 , tmp);
                --num_br;
        }
        bool f = true;
        for(int i = 0 ; i < s.size() ; ++i){
            if(s[i]>'9' || s[i]<'0' ) f = false; 
        }
        if(f) ans.push_back(stoi(s)); 
        else ans.push_back(calc(s));
        --t;
    }
    reverse(ALL(ans));
    for(int i = n - 1 ; i >=0 ; --i) cout << ans[i] << endl;
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <map>
#include <vector>

using namespace std;

int main(){
    int n;
    string q, a, sop;
    stack<int> numstack;
    stack<string> opstack;
    map<string, int> oprank;
	vector<string> exq;
    oprank["/"] = oprank["*"] = 2;
    oprank["+"] = oprank["-"] = 1;
	oprank["("] = 0;
    cin >> n;
    for(int i(0);i < n;++i){
        cin >> q;
		exq.clear();
        a = "";
        for(int j(0);j < q.length();++j){
            if(q[j] < '0' || '9' < q[j]){
                if(a.length() > 0) exq.push_back(a);
                a = "";
				sop = string(1, q[j]);
                if(opstack.empty()){
					opstack.push(sop);
					continue;
				}
				if(sop == ")"){
					while(opstack.top() != "("){
						exq.push_back(opstack.top());
						opstack.pop();
					}
					opstack.pop();
				}
				else if(sop == "(") opstack.push(sop);
				else if(sop == "="){
					while(!opstack.empty()){
						exq.push_back(opstack.top());
						opstack.pop();
					}
				}
				else if(oprank[sop] <= oprank[opstack.top()]){
					while(!opstack.empty() && oprank[sop] <= oprank[opstack.top()]){
						exq.push_back(opstack.top());
						opstack.pop();
					}
					opstack.push(sop);
				}
				else opstack.push(sop);
            }
            else a += q[j];
        }
		for(string s : exq){
			if(s[0] < '0' || '9' < s[0]){
				int x, y;
				y = numstack.top();
				numstack.pop();
				x = numstack.top();
				numstack.pop();
				if(s == "+"){
					numstack.push(x + y);
				}
				else if(s == "-"){
					numstack.push(x - y);
				}
				else if(s == "*"){
					numstack.push(x * y);
				}
				else if(s == "/"){
					numstack.push(x / y);
				}
			}
			else numstack.push(stoi(s));
		}
		cout << numstack.top() << endl;
		numstack.pop();
    }
    return 0;
}

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

ll stol(string s){
  stringstream ss(s);
  ll n;
  ss >> n;
  return n;
}

ll parse(int l, int r){
  int n = 0,i;

  for(i=r-1;i>=l;i--){
    if(s[i] == ‘)‘)n++;  if(s[i] == ‘(’)n--;
    if(!n){
      if(s[i] == ‘+’)return parse(l,i)+parse(i+1,r);
      if(s[i] == ‘-’)return parse(l,i)-parse(i+1,r);
    }
  }

  for(i=r-1;i>=l;i--){
    if(s[i] == ‘)‘)n++;  if(s[i] == ‘(’)n--;
    if(!n){
      if(s[i] == ‘*’)return parse(l,i)*parse(i+1,r);
      if(s[i] == ‘/’)return parse(l,i)/parse(i+1,r);
    }
  }

  if(s[l] == ‘(‘ && s[r-1] == ‘)’)return parse(l+1,r-1);
  return stol(s.substr(l,r-l));
}

int main(){
  int n;
  string s;
  cin >> n;
  while(n--){
    cin >> s;
    cout << parse(0,(int)s.size()-1) << endl;
  }
}