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;
		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+=(buf.top()).second;
						buf.pop();
						buf.push(MP(i,str[i]));
					}else{
						temp+=(buf2.top()).second;
						buf2.pop();
						buf2.push(MP(i,str[i]));
					}
				}
			}else if(str[i]=='*'||str[i]=='/'){
				if(!ch){
					buf.push(MP(300-i,str[i]));
				}else{
					buf2.push(MP(300-i,str[i]));
				}
			}else if(str[i]=='('){
				ch=true;
			}else if(str[i]==')'){
				while(!buf2.empty()){
					temp+=(buf2.top()).second;
					buf2.pop();
				}
				ch=false;
			}else if(str[i]=='='){
				while(!buf.empty()){
					temp+=(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+=toString(t);
					t=0;
				}
			}
		}
		stack <int> st;
		REP(i,SZ(temp)){
			if(temp[i]>='0'&&temp[i]<='9'){
				st.push((unsigned int)(temp[i]-'0'));
			}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 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(t2/t1);
			}
		}
		res.PB(st.top());
	}
	REP(i,N)cout<<res[i]<<endl;
	return 0;
}

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

C++: //18
#include<iostream>
#include<cctype>

using namespace std;

char s[101];
char *p;

int pp();
int pm();
int pb();

int pp(){
  int a=pm();
  while(*p=='+'||*p=='-'){
    char o=*p++;
    int b=pm();
    if(o=='+'){
      a+=b;
    }else{
      a-=b;
    }
  }
  return a;
}

int pm(){
  int a=pb();
  while(*p=='*'||*p=='/'){
    char o=*p++;
    int b=pb();
    if(o=='*'){
      a*=b;
    }else{
      a/=b;
    }
  }
  return a;
}

int pb(){
  if(*p=='('){
    p++;
    int a=pp();
    p++;
    return a;
  }else{
    int a=0;
    while(isdigit(*p)){
      a=a*10+*p-'0';
      p++;
    }
    return a;
  }
}

int main(){
  int n;
  cin>>n;
  while(n--){
    cin>>s;
    p=s;
    cout<<pp()<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int digits(auto& i) {
  int res = 0;
  while (isdigit(*i)) res = 10 * res + *i++ - '0';
  return res;
}
int expr(auto& i);
int num(auto& i) {
  switch (*i) {
    case '+': return num(++i);
    case '-': return -num(++i);
    case '(': {
      int res = expr(++i);
      return ++i, res;
    }
    default: return digits(i);
  }
}
int term(auto& i) {
  int res = num(i);
  while (true) switch (*i) {
    case '*': res *= num(++i); break;
    case '/': res /= num(++i); break;
    default: return res;
  }
}
int expr(auto& i) {
  int res = term(i);
  while (true) switch (*i) {
    case '+': res += term(++i); break;
    case '-': res -= term(++i); break;
    default: return res;
  }
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  while (n--) {
    string s; cin >> s;
    auto i = begin(s);
    cout << expr(i) << '\n';
  }
}