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 <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef complex<double> xy_t;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

const lint mod = 1e9+7;
const lint INF = mod;
const int MAX = 100010;

int expression(string &s, int &idx);
int term(string &s, int &idx);
int factor(string &s, int &idx);
int number(string &s, int &idx);

int expression(string &s, int &idx){
    int ret=term(s, idx);
    while(true) {
        if (s[idx]=='+') ++idx, ret+=term(s, idx);
        else if(s[idx]=='-') ++idx, ret-=term(s, idx);
        else break;
    }
    return ret;
}

int term(string &s, int &idx){
    int ret=factor(s, idx);
    while(true) {
        if (s[idx]=='*') ++idx, ret*=factor(s, idx);
        else if(s[idx]=='/') ++idx, ret/=factor(s, idx);
        else break;
    }
    return ret;
}

int factor(string &s, int &idx){
    if(s[idx]=='('){
        ++idx;
        int ret=expression(s, idx);
        ++idx;
        return ret;
    }
    else return number(s, idx);
}

int number(string &s, int &idx){
    int ret=0;
    while(0<=s[idx]-'0' && s[idx]-'0'<=9){
        ret=ret*10+(s[idx]-'0');
        ++idx;
    }
    return ret;
}

int main(){
    int q;
    scanf("%d", &q);
    while(q--){
        string s;
        cin >> s;
        int idx=0;
        printf("%d\n", expression(s, idx));
    }
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

typedef pair<ll,const char*> parsed;

parsed expr(const char*);
parsed term(const char*);
parsed fact(const char*);

parsed expr(const char* s)
{
	//cout<<"expr(\""<<s<<"\")"<<endl;
	parsed now=term(s);
	//while(*now.second!='=' && *now.second!=')'){
	while(*now.second=='+' || *now.second=='-'){
		char op=*now.second;
		parsed next=term(now.second+1);
		if(op=='+')
			now=parsed(now.first+next.first,next.second);
		else
			now=parsed(now.first-next.first,next.second);
	}
	//cout<<"expr(\""<<s<<"\")="<<now.first<<endl;
	return now;
}

parsed term(const char* s)
{
	//cout<<"term(\""<<s<<"\")"<<endl;
	parsed now=fact(s);
	//while(*now.second!='=' && *now.second!=')' && *now.second!='+' && *now.second!='-'){
	while(*now.second=='*' || *now.second=='/'){
		char op=*now.second;
		parsed next=fact(now.second+1);
		if(op=='*')
			now=parsed(now.first*next.first,next.second);
		else
			now=parsed(now.first/next.first,next.second);
	}
	//cout<<"term(\""<<s<<"\")="<<now.first<<endl;
	return now;
}

//parsed fact(const char* s)
//{
//	//cout<<"fact(\""<<s<<"\")"<<endl;
//	if(s[0]=='('){
//		parsed res=expr(s+1);
//		res.second++;
//		return res;
//	}
//	else{
//		const char* p=s;
//		if(*p=='-')
//			p++;
//		ll n=0;
//		while(isdigit(*p)){
//			n=n*10+*p-'0';
//			p++;
//		}
//		return parsed(n,p);
//	}
//}

//parsed expr(const char *p)
//{
//  parsed r=term(p);
//  while(*r.second=='+'||*r.second=='-'){
//    char op=*r.second;
//    int tmp=r.first;
//    r=term(r.second+1);
//    if (op=='+') r.first=tmp+r.first;
//    else r.first=tmp-r.first;
//  }
//  return r;
//}
//
//parsed term(const char *p)
//{
//  parsed r=fact(p);
//  while(*r.second=='*'||*r.second=='/'){
//    char op=*r.second;
//    int tmp=r.first;
//    r=fact(r.second+1);
//    if (op=='*') r.first=tmp*r.first;
//    else r.first=tmp/r.first;
//  }
//  return r;
//}

parsed fact(const char *p)
{
  if (isdigit(*p)){
    int t=*(p++)-'0';
    while(isdigit(*p)) t=t*10+*(p++)-'0';
    return parsed(t,p);
  }
  else if (*p=='('){
    parsed r=expr(p+1);
    if (*r.second!=')') exit(0); // invalid input
    return parsed(r.first,r.second+1);
  }
  else
    exit(0); // invalid input
}

int main()
{
	//const char* s="-6/-4=";
	//parsed p=expr(s);
	//cout<<p.first<<","<<p.second<<endl;
	
	string s;
	getline(cin,s);
	while(getline(cin,s))
		cout<<expr(s.c_str()).first<<endl;
	
	return 0;
}

C++: // g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#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;
		State begin=s.begin();
		cout<<expr(begin)<<endl;
	}
}