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<cctype> // isdigit
#include<cassert> // assert
using namespace std;

struct Result{int value,pos;};

int calculate(string expression);
Result equation(string expression,int pos);
Result factor(string expression,int pos);
Result term(string expression,int pos);

int calculate(string expression)
{
  return equation(expression,0).value;
}

Result equation(string expression,int pos)
{
  Result r=factor(expression,pos);
  // Á¸Z
  while(expression[r.pos]=='+' || expression[r.pos]=='-'){
    Result _r=factor(expression,r.pos+1);
    if(expression[r.pos]=='+')r.value += _r.value;
    if(expression[r.pos]=='-')r.value -= _r.value;
    r.pos=_r.pos;
  }
  return r;
}
Result factor(string expression,int pos)
{
  Result r=term(expression,pos);
  // æZ
  while(expression[r.pos]=='*' || expression[r.pos]=='/'){
    Result _r=term(expression,r.pos+1);
    if(expression[r.pos]=='*')r.value *= _r.value;
    if(expression[r.pos]=='/')r.value /= _r.value;
    r.pos=_r.pos;
  }
  return r;
}
Result term(string expression,int pos)
{
  Result r;
  // l
  if(isdigit(expression[pos])){
    int value=0;
    while(isdigit(expression[pos]))value += value*10 + expression[pos++]-'0';
    r.value=value;
    r.pos=pos;
    return r;
  }
  // Ê
  if(expression[pos]=='('){
    r=equation(expression,pos+1);
    assert(expression[r.pos++]==')');
    return r;
  }
}

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

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define INF 1000000


int ar[2][14];
int main(){
	string str;
	int N;
	cin>>N;
	VI res;
	stack <string>st;
	REP(ii,N){
		cin>>str;
		priority_queue<pair<int,char> > buf;
		priority_queue<pair<int,char> > buf2;
		
		bool ch=false;
		int t=0;
		vector<string> temp;
		REP(i,SZ(str)){
			if(str[i]=='+'||str[i]=='-'){
				if((!ch&&(buf.empty()||(buf.top()).first<i))||(ch&&(buf2.empty()||(buf2.top()).first<i))){
					if(!ch){
						buf.push(MP(i,str[i]));
					}else{
						buf2.push(MP(i,str[i]));
					}
				}else{
					if(!ch){
						temp.PB(toString((buf.top()).second));
						buf.pop();
						buf.push(MP(i,str[i]));
					}else{
						temp.PB(toString((buf2.top()).second));
						buf2.pop();
						buf2.push(MP(i,str[i]));
					}
				}
			}else if(str[i]=='*'||str[i]=='/'){
				if(!ch){
					buf.push(MP(100+i,str[i]));
				}else{
					buf2.push(MP(100+i,str[i]));
				}
			}else if(str[i]=='('){
				ch=true;
			}else if(str[i]==')'){
				while(!buf2.empty()){
					temp.PB(toString((buf2.top()).second));
					buf2.pop();
				}
				ch=false;
			}else if(str[i]=='='){
				while(!buf.empty()){
					temp.PB(toString((buf.top()).second));
					buf.pop();
				}
			}else if(str[i]>='0'&&str[i]<='9'){
				if(i+1<SZ(str)&&str[i+1]>='0'&&str[i+1]<='9'){
					t+=(unsigned int)(str[i]-'0');
					t*=10;
				}else{
					t+=(unsigned int)(str[i]-'0');
					//cout<<t<<endl;
					temp.PB(toString(t));
					t=0;
				}
			}
		}
		REP(i,SZ(temp))cout<<temp[i];
		cout<<endl;
		stack <int> st;
		/*REP(i,SZ(temp)){
			if(temp[i]=="+"){
				int t1=st.top();
				st.pop();
				int t2=st.top();
				st.pop();
				st.push(t1+t2);
			}else if(temp[i]=="-"){
				int t1=st.top();
				st.pop();
				int t2=st.top();
				st.pop();
				st.push(t2-t1);
			}else if(temp[i]=="*"){
				int t1=st.top();
				st.pop();
				int t2=st.top();
				st.pop();
				st.push(t1*t2);
			}else if(temp[i]=="/"){
				int t1=st.top();
				st.pop();
				int t2=st.top();
				st.pop();
				st.push(t2/t1);
			}else{
				st.push(toInt(temp[i]));
			}
		}*/
		cout<<"0"<<endl;
		//st.pop();
		
	}
	return 0;
}

/*
4
5+4*3+2/6=
(1+4)*(3+7)/5=
5+4-3=
(1+5)*(2+3)=
*/

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



int calculator(const string &s){
	int sta[100],sp=0;
	bool isnum[100];
	for(int i=0;i<s.size();){
		if(s[i]=='=')break;
		if(s[i]=='('){
			sta[sp]='(';
			isnum[sp++]=false;
			i++;
		}else if(s[i]==')'){
			int a,b;
			b=sta[--sp];
			while(sta[sp-1]!='('){
				char op=sta[--sp];
				a=sta[--sp];
				if(op=='+')b=a+b;
				else b=a-b;
			}
			sp--;
			while(sp&&!isnum[sp-1]&&(sta[sp-1]=='*'|| sta[sp-1]=='/') ){
				char op=sta[--sp];
				a=sta[--sp];
				if(op=='*')b=a*b;
				else b=a/b;
			}
			sta[sp]=b;
			isnum[sp++]=true;
			i++;
		}else if(s[i]=='+'||s[i]=='-'||s[i]=='*'||s[i]=='/'){
			sta[sp]=s[i];
			isnum[sp++]=false;
			i++;
		}else {
			int n=0;
			bool minus=false;
			if(s[i]=='-')minus=true,i++;
			while(isdigit(s[i]))n+=n*10+s[i++]-'0';
			if(minus)n=-n;
			int a,b=n;
			if(2<=sp&&!isnum[sp-2]&&sta[sp-1]=='-'){
				sta[sp-1]=-n;
				isnum[sp-1]=true;
			}
			else {
				while(sp&&!isnum[sp-1]&&(sta[sp-1]=='*'|| sta[sp-1]=='/') ){
					char op=sta[--sp];
					a=sta[--sp];
					if(op=='*')b=a*b;
					else b=a/b;
				}
				sta[sp++]=b;			
			}
		}
	}
	int a,b;
	b=sta[--sp];
	while(sp){
		char op=sta[--sp];
		a=sta[--sp];
		if(op=='+')b=a+b;
		else b=a-b;
	}
	return b;
}

int main(){
	int n;
	string s;
	cin>>n;
	while(n--){
		cin>>s;
		cout<<calculator(s)<<endl;
	}
	return 0;
}