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 <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a,b) (abs((a)-(b)) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef complex<double> Point;
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;


class Arithmetic{
public:
	string str;
	int n, flag = 1;
	void init(string s){str = s;n = str.size();}
	int add(int a, int b){return a+b;}
	int mul(int a, int b){return a*b;}
	int div(int a, int b){return a/b;}
  int sur(int a, int b){return a%b;}
	
	P get_num(int p){
		int ans = 0, q = -1, f = 0;
		if(str[p] == '(')return calc(p+1, 0);
		if(str[p] == '-'){f = 1;p++;}
		if(str[p] == '('){P pi = calc(p+1, 0);return P(-pi.fi, pi.se);}
		repi(i,p,n){
			if(!isdigit(str[i]))break;
			ans = ans*10+(str[i]-'0');q = i;
		}
		if(f)return P(-ans, q);
		return P(ans, q);
	}
	
	P calc(int pp = 0, int f = 0){
		P pi = get_num(pp);
		int ans = pi.fi, p = pi.se+1;
		repi(i,p,n){
			if(f and str[i] == ')')return P(ans, i-1);
			if(str[i] == ')')return P(ans, i);
			if(str[i] == '*' or str[i] == '/' or str[i] == '%'){
				pi = get_num(i+1);
				if(str[i] == '*')ans = mul(ans, pi.fi);
				if(str[i] == '/')ans = div(ans, pi.fi);
        if(str[i] == '%')ans = sur(ans, pi.fi);
			}
			if(str[i] == '+' or str[i] == '-'){
				if(f)return P(ans, i-1);
				if(str[i] == '+')pi = calc(i+1, 1);
				if(str[i] == '-')pi = calc(i, 1);
				ans = add(ans, pi.fi);
			}
			i = pi.se;
		}
		return P(ans, n-1);
	}
	int solve(int ret = -INF){	//0除算のとき返す値
		flag = 1;
		P ans = calc();
		if(!flag)return ret;
		return ans.fi;
	}
};

signed main(){
  int n;
  scanf("%lld", &n);
  rep(i,n){
    string str;
    cin >> str;
    str.pop_back();
    Arithmetic A;
    A.init(str);
    int ans = A.solve();
    cout << ans << endl;
  }
	return 0;
}