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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

char e[128];
int p;

int exp();
int term();
int fact();

int exp(){
  int ret = term();
  while(e[p] == '+' || e[p] == '-'){
    if(e[p] == '+'){
      p++;
      ret += term();
    }else if(e[p] == '-'){
      p++;
      ret -= term();
    }
  }
  return ret;
}

int term(){
  int ret = fact();
  while(e[p] == '*' || e[p] == '/'){
    if(e[p] == '*'){
      p++;
      ret *= fact();
    }else if(e[p] == '/'){
      p++;
      ret /= fact();
    }
  }
  return ret;
}

int fact(){
  int ret = 0;
  if(e[p] == '('){
    p++;
    ret = exp();
    p++;
  }
  while(isdigit(e[p])){
    ret = ret * 10 + e[p] - '0';
    p++;
  }
  return ret;
}

int main(){
  int n;
  scanf("%d", &n);
  while(n--){
    scanf("%s", e);
    p = 0;
    printf("%d\n", exp());
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

string get_term(string, int&);
int get_num(string);
int get_exp(string);

int get_num(string str) {
    int num = 0;

    if (str.size() == 0) return 0;

    int i = 0;
    if (str[i] == '(') {
        i++;
        string exp;
        for (int count = 1; count; i++) {
            if (str[i] == '(') count++;
            if (str[i] == ')') count--;
            if (count) exp += str[i];
        }

        num = get_exp(exp + "=");
    } else {
        for (; i < str.size() && '0' <= str[i] && str[i] < '9'; i++) {
            num = num * 10 + (str[i] - '0');
        }
    }

    for (; i < str.size(); i++) {
        if (str[i] == '*') {
            i++;
            int tmp = 0;
            for (; i < str.size() && '0' <= str[i] && str[i] < '9'; i++) {
                tmp = tmp * 10 + (str[i] - '0');
            }
            num *= tmp;
            i--;
        } else {
            i++;
            int tmp = 0;
            for (; i < str.size() && '0' <= str[i] && str[i] < '9'; i++) {
                tmp = tmp * 10 + (str[i] - '0');
            }
            num /= tmp;
            i--;
        }
    }

    return num;
}


void solve(string str) {
    cout << get_exp(str) << endl;
}

int main() {
    int N;
    cin >> N;

    while (N--) {
        string str;
        cin >> str;
        solve(str);
    }

    return 0;
}

string get_term(string str, int& i) {
    string init_str;
    for (int count = 0; i < str.size(); i++) {
        if (str[i] == '(') count++;
        if (count > 0 || ('0' <= str[i] && str[i] <= '9') || str[i] == '/' || str[i] == '*') {
            init_str += str[i];
        }
        if (str[i] == ')') count--;

        if (count == 0 && (str[i] == '+'|| str[i] == '-' || str[i] == '=')) {
            break;
        }
    }

    return init_str;
}

int get_exp(string str) {
    int num  = 0;
    int i = 0;

    string init_str = get_term(str, i);
    num = get_num(init_str);

    while (str[i] != '=') {
        if (str[i] == '-') {
            i++;
            string term = get_term(str, i);
            num -= get_num(term);
        } else if (str[i] == '+') {
            i++;
            string term = get_term(str, i);
            num += get_num(term);
        }
    }

    return num;
}

C++: #include<bits/stdc++.h>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)


typedef long long ll;


int lp;
int lpcnt = 0;


string str;

bool input(){

  if(lpcnt==0)cin>>lp;

  if(lpcnt==lp)return false;
  cin>>str;

  lpcnt++;
  return true;
}


class S{
public:
  bool isnum;
  bool isc;
  char c;
  int num;
  S(bool isnum, bool isc, char c, int num):isnum(isnum),isc(isc),c(c),num(num){}
  S(){isnum=isc=false; c='#'; num=0;}
  void print(){
    printf("%d %d %d %c\n",isnum,isc,num,c);
  }
};

typedef pair<int,string> pis;
typedef pair<char,string> pcs;

bool isnum(char c){
  return '0'<=c && c<='9';
}

int ctonum(char c){
  return c-'0';
}

pis getHeadNum(string str){

  pis ret = pis(0,"");
  int st = 0;
  while(str.size()!=st && isnum(str[st])){
    ret.first *= 10;
    ret.first += ctonum(str[st]);
    st++;
  }

  ret.second = str.substr(st);
  return ret;
}

pcs getHeadChar(string str){
  return pcs(str[0], str.substr(1));
}

bool iscalc(char c){
  if(c=='*' || c=='+' || c=='-' || c=='/')return true;
  return false;
}


vector<S> getEq(string str){
  vector<S> eq;
  string sc = str;
  eq.clear();

  while(sc.size()!=0){
    int hu = 1;
    S add;
    if(sc[0]=='-' && ((eq.size()!=0 && iscalc(eq[eq.size()-1].c))||eq.size()==0)){
      hu = -1;
      sc = sc.substr(1);
    }
    if(isnum(sc[0])){
      add.isnum = true;
      pis res = getHeadNum(sc);
      add.num = hu*res.first;
      sc = res.second;
    }else{
      add.isc = true;
      pcs res = getHeadChar(sc);
      add.c = res.first;
      sc = res.second;
    }
    eq.push_back(add);
  }
  return eq;
}

int calc(int st, int en, vector<S>& eq){
  
  /*
  
  for(int i=st;i<en;i++){
    eq[i].print();
  }puts("");
  */



  if(st>=en){
    printf("%d %d\n",st,en);
    assert(0);
  }

  int num = eq[st].num;
  if(st+1==en)return num;
  int a=0;

  reps(i,st,en){

    if(eq[i].c=='(')a++;
    if(eq[i].c==')')a--;


    if(a==0){
      if(eq[i].c=='-'){
	return calc(st, i, eq) - calc(i+1, en, eq);
      }
      if(eq[i].c=='+'){
	return calc(st, i, eq) + calc(i+1, en, eq);
      }
    }

  }

  a=0;

  reps(i,st, en){

    if(eq[i].c=='(')a++;
    if(eq[i].c==')')a--;
    if(a==0){
      if(eq[i].c=='*'){
	return calc(st, i, eq) * calc(i+1, en, eq);
      }
      if(eq[i].c=='/'){
	return calc(st, i, eq) / calc(i+1, en, eq);
      }
    }

  }

  if(eq[st].c=='('){
    return calc(st+1, en-1, eq);
  }
  puts("AAA");
  assert(0);
  return -1;
  
}
int solve(){
  vector<S> eq = getEq(str);
  return calc(0,eq.size()-1, eq);
}

int main(){
  while(input()){
    cout<<solve()<<endl;
  }
}