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
//------------------------------------------
#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();
				if(t1!=0)st.push(t2/t1);
				else st.push(0);
			}else{
				st.push(toInt(temp[i]));
			}
		}
		cout<<st.top()<<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<cctype>
#define I int
I E();std::string S;I P,V;I T(){for(V=0;isdigit(S[P]);)V=V*10+S[P++]-48;return S[P]-40?V:++P?E():0;}I F(){I a=T();for(;S[P]==42|S[P]==47;)a=S[P++]-47?a*=T():a/=T();return a;}I E(){I a=F();for(;S[P]==43|S[P]==45;)a+=-(S[P++]==45)*F();return a;}main(){for(std::cin>>P;std::cin>>S;printf("%d\n",E()))S[S.size()-1]=P=0;}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int calc(char *s, int &i){
  int ret = 0;
  bool flag = i >= 0 && s[i-1] == '(';
  
  for(;s[i];){
    
    if(s[i] == ')'){
      if(flag) i++;
      return ret;
    }
    
    if(s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/'){

      i++;
      
      if(s[i] == '('){
        i++;

        if(i-2 < 0) ret += calc(s,i);
        if(s[i-2] == '+') ret += calc(s,i);
        if(s[i-2] == '-') ret -= calc(s,i);
        if(s[i-2] == '*') ret *= calc(s,i);
        if(s[i-2] == '/') ret /= calc(s,i);

        continue;
      }

            
      if(s[i-1] == '+') ret += calc(s,i);
      if(s[i-1] == '-') ret -= calc(s,i);
      
    }else{
      int start = i-1;
      int sum = 0;
      
      while(!(s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/' || s[i] == '\0' || s[i] == ')')){
        sum *= 10;
        sum += s[i] - '0';
        i++;
      }

      if(start < 0){
        ret += sum;
      }else{
        if(s[start] == '(') ret += sum;
        if(s[start] == '+') ret += sum;
        if(s[start] == '-') ret += sum;
        if(s[start] == '*') ret *= sum;
        if(s[start] == '/') ret /= sum;
      }
    }
  }
  
  return ret;
}


int main(){
  char s[SIZE],s2[SIZE];
  int t = 0;

  int n;

  scanf("%d",&n);

  while(n--){
    t = 0;
    scanf("%s",s);

    s[strlen(s)-1] = '\0';

    strcat(s2,"0+");
    strcat(s2,s);
    
    printf("%d\n",calc(s2,t));
  }
  
  return 0;
}