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 <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<ll, string> PLS;

int n;
string s;

int changei(string t){
	int res;
	stringstream ss;
	ss << t;
	ss >> res;
	return res;
}

string changes(int num){
	string res;
	stringstream ss;
	ss << num;
	ss >> res;
	return res;
}

string s_calc(string t){
	string res = t;
	REP(i, res.size()){
		if (res[i] == '*' || res[i] == '/'){
			int num1, pos1, pos2, size1, size2;
			for (int j = i - 1;; j--){
				if (res[j] == '+' || res[j] == '-' || res[j] == '*' || res[j] == '/'){
					size1 = res.substr(j + 1, i - j - 1).size();
					num1 = changei(res.substr(j + 1, i - j - 1));
					break;
				}
				if (j == 0){
					pos1 = j;
					size1 = res.substr(0, i).size();
					num1 = changei(res.substr(0, i));
					break;
				}
				pos1 = j;
			}
			for (int j = i + 1;; j++){
				if (j != i + 1){
					if (res[j] == '+' || res[j] == '-' || res[j] == '*' || res[j] == '/'){
						if (res[i] == '*')num1 *= changei(res.substr(i + 1, j - (i + 1)));
						else num1 /= changei(res.substr(i + 1, j - (i + 1)));
						size2 = changes(num1).size();
						break;
					}
				}
				if (j == res.size() - 1){
					pos2 = j;
					if (res[i] == '*')num1 *= changei(res.substr(i + 1, j - (i + 1) + 1));
					else num1 /= changei(res.substr(i + 1, j - (i + 1) + 1));
					size2 = changes(num1).size();
					break;
				}
				pos2 = j;
			}
			if (pos2 != res.size() - 1){
				res = res.substr(0, pos1) + changes(num1)
					+ res.substr(pos2 + 1, res.size() - 1 - pos2);
			}
			else{
				res = res.substr(0, pos1) + changes(num1);
			}
			i = i - size1 + size2 - 1;
		}
	}

	//cout << "!!" << res << endl;

	REP(i, res.size()){
		if (res[i] == '+' || res[i] == '-'){
			if (i == 0)continue;
			int num1, pos1, pos2, size1, size2;
			for (int j = i - 1;; j--){
				if (res[j] == '+' || res[j] == '-'){
					if (j != 0)num1 = changei(res.substr(j + 1, i - j - 1));
					else {
						pos1 = j;
						size1 = res.substr(j, i - j).size();
						num1 = changei(res.substr(j, i - j));
					}
					break;
				}
				if (j == 0){
					pos1 = j;
					size1 = res.substr(0, i).size();
					num1 = changei(res.substr(0, i));
					break;
				}
				pos1 = j;
			}
			for (int j = i + 1;; j++){
				if (res[j] == '+' || res[j] == '-'){
					if (res[i] == '+')num1 += changei(res.substr(i + 1, j - (i + 1)));
					else num1 -= changei(res.substr(i + 1, j - (i + 1)));
					size2 = changes(num1).size();
					break;
				}
				if (j == res.size() - 1){
					pos2 = j;
					if (res[i] == '+')num1 += changei(res.substr(i + 1, j - (i + 1) + 1));
					else num1 -= changei(res.substr(i + 1, j - (i + 1) + 1));
					size2 = changes(num1).size();
					break;
				}
				pos2 = j;
			}
			if (pos2 != res.size() - 1){
				res = res.substr(0, pos1) + changes(num1)
					+ res.substr(pos2 + 1, res.size() - 1 - pos2);
			}
			else{
				res = res.substr(0, pos1) + changes(num1);
			}
			i = i - size1 + size2 - 1;
		}
		//cout << t << endl;
	}
	return res;
}

string solve(string t){
	string res = t;
	REP(i, res.size()){
		//cout << "!!" << i  << endl;
		//cout << res << endl;
		int pos1, pos2, size;
		if (res[i] == ')'){
			pos2 = i;
			for (int j = i; j >= 0; j--){
				if (res[j] == '('){
					pos1 = j;
					//cout << res.substr(pos1 + 1, pos2 - pos1 - 1) << endl;
					string buf = s_calc(res.substr(pos1 + 1, pos2 - pos1 - 1));
					size = buf.size();
					if (pos2 == res.size() - 1)res = res.substr(0, pos1) + buf;
					else res = res.substr(0, pos1) + buf + res.substr(pos2 + 1, res.size() - pos2 - 1);
					break;
				}
			}
			i = pos1 + size - 1;
			//cout << "!" << i << endl;
		}
	}
	//cout << res << endl;
	return res;
}

int main(){
	cin >> n;
	REP(i, n){
		cin >> s;
		s.pop_back();
		cout << s_calc(solve(s)) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <vector>
#include <stdio.h>

using namespace std;

int getPriority(char ch){
  switch(ch){
  case '+':
    return 0;
  case '-':
    return 1;
  case '*':
    return 2;
  case '/':
    return 3;
  default:
    return -1;
  }
}

vector<string> toReversePorland(string str){

  vector<string> hand;
  vector<string> side;
  
  for(int i = 0; i < str.size(); i++){
    if(str[i] == ' ')
      continue;
    else if(str[i] == '=')
      break;
    if(str[i] >= '0' && str[i] <= '9'){
      string num;
      while(i < str.size()){
	if(str[i] < '0' || str[i] > '9'){
	  break;
	}
	num += str[i];
	i++;
      }
      hand.push_back(num);
      i--;
    }
    else if(str[i] == '('){
      string tmp;
      tmp += str[i];
      side.push_back(tmp);
    }
    else if(str[i] == ')'){
      // ツ右ツ環古環づ慊づ可可算ツ子ツづーツ暗ェツづつつクツづつ偲ィツ個ウツづ可姪淞つキ
      for(int j = side.size()-1 ; ;j--){
	if(side[j] == "("){
	  if(j != 0){
	    vector<string> tmp;
	    for(int k = 0; k < j; k++){
	      tmp.push_back(side[k]);
	    }
	    side = tmp;
	  }
	  else
	    side.clear();
	  break;
	}
	else{
	  string tmp = side[j];
	  hand.push_back(tmp);
	}
      }
    }
    else{
      if(side.size() == 0){
	string tmp;
	tmp += str[i];
	side.push_back(tmp);
      }
      else{
	char cs = side[side.size()-1][0];
	if(cs != '+' && cs != '-' && cs != '*' && cs != '/'){
	  string tmp;
	  tmp += str[i];
	  side.push_back(tmp);
	}
	else{
	  if(getPriority(str[i]) < getPriority(cs)){
	    hand.push_back(side[side.size()-1]);
	    string tmp;
	    tmp += str[i];
	    side[side.size()-1] = tmp;
	  }
	  else{
	    string tmp;
	    tmp += str[i];
	    side.push_back(tmp);
	  }
	}
      }
    }
  }

  for(int i = side.size()-1; i >= 0; i--){
    string tmp;
    hand.push_back(side[i]);
  }
  return hand;
}


long long calc(vector<string> str){
  stack<long long> st;
  for(int i = 0; i < str.size(); i++){
    if(str[i] == "+" || str[i] == "-" || str[i] == "*" || str[i] == "/"){
      long long val[2];
      val[0] = st.top();
      st.pop();
      val[1] = st.top();
      st.pop();
      if(str[i] == "+"){
	st.push(val[0] + val[1]);
      }
      if(str[i] == "-"){
	st.push(val[1] - val[0]);
      }
      if(str[i] == "*"){
	st.push(val[0] * val[1]);
      }
      if(str[i] == "/"){
	st.push(val[1] / val[0]);
      }
    }
    else{
      st.push(atoi(str[i].c_str()));
    }
  }
  return st.top();
}

int main(){

  int n;
  string s;
  cin >> n;
  
  vector<string> input;
  string str;
  for(int i = 0; i < n; i++){
    cin >> str;
    input.push_back(str);
  }

  for(int i = 0; i < n; i++){
    str = input[i];
    // vector<string> vec = toReversePorland(str);
    // for(int i = 0; i < vec.size(); i++)
    //   cout << vec[i] << endl;
    cout << calc(toReversePorland(str)) << endl;
  }
  
  return 0;
}