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] == '/'){
					if (j != 0){
						size1 = res.substr(j + 1, i - j - 1).size();
						num1 = changei(res.substr(j + 1, i - j - 1));
					}
					else{
						pos1 = j;
						size1 = i;
						num1 = changei(res.substr(0, i));
					}
					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 <sstream>
using namespace std;

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


string foo2(string s){
	// cout<<s<<endl;
	bool f=true;
	rep(i,s.size()){
		if(i==0){
			if(s[0]=='-');
			else f=false;
		}
		else{
			if(s[i]>='0'&&s[i]<='9'){

			}
			else{
				f=false;
			}
		}
	}
	if(f) return s;
	// bool f=false;
	rep(i,s.size()){
		if(s[i]=='*'||s[i]=='/'){
			int xl=i,xr=i;
			f=true;
			while(1){
				if(xl==0) break;
				else if(s[xl-1]>='0'&&s[xl-1]<='9'){
					xl--;
				}
				else{
					
					break;
				}
			}
			while(1){
				if(xr==s.size()-1) break;
				else if(s[xr+1]>='0'&&s[xr+1]<='9'){
					xr++;
				}
				else{
					
					break;
				}
			}
			stringstream ss1,ss2;
			// cout<<s.substr(xl,xr-xl+1)<<endl;
			ss1<<s.substr(xl,xr-xl+1);
			int a,b;
			char t;
			ss1>>a;
			// cout<<"a "<<a<<endl;
			ss1>>t;
			ss1>>b;
			ss2<<s.substr(0,xl);
			int tt;
			if(t=='*'){
				tt=a*b;
			}
			else{
				tt=a/b;
			}
			ss2<<tt;
			 if(xr<s.size()-1) ss2<<s.substr(xr+1);
			ss2>>s;
			string tmp;
			// cout<<"foo2 "<<s<<" "<<endl;
			return foo2(tmp);
		}
	}
	rep(i,s.size()){
		if(s[i]=='+'||s[i]=='-'){
			int xl=i,xr=i;
			f=true;
			while(1){
				if(xl==0) break;
				else if(s[xl-1]>='0'&&s[xl-1]<='9'){
					xl--;
				}
				else{
					break;
				}
			}
			while(1){
				if(xr==s.size()-1) break;
				else if(s[xr+1]>='0'&&s[xr+1]<='9'){
					xr++;
				}
				else{
					break;
				}
			}
			stringstream ss1,ss2;
			ss1<<s.substr(xl,xr-xl+1);
			int a,b;
			char t;
			ss1>>a;
			ss1>>t;
			ss1>>b;
			ss2<<s.substr(0,xl);
			int tt;
			if(t=='+'){
				tt=a+b;
			}
			else{
				tt=a-b;
				// cout<<tt<<endl;
			}
			ss2<<tt;
			 if(xr<s.size()-1) ss2<<s.substr(xr+1);
			string tmp;
			ss2>>tmp;
			return foo2(tmp);
		}
	}
	return s;
}

string foo1(string s){
	// cout<<s<<endl;
	int xl=-1,xr=-1;
	rep(i,s.size()){
		if(s[i]=='('){
			xl=i;
		}
		else if(s[i]==')'){
			xr=i;
			break;
		}
	}
	if(xr!=-1){
		// if(xr>=s.size()-1) return foo1(s.substr(0,xl)+s.substr(xl+1,xr-xl-1));
		if(xr>=s.size()-1) return foo1(s.substr(0,xl)+foo2(s.substr(xl+1,xr-xl-1)));
		// return foo1(s.substr(0,xl)+s.substr(xl+1,xr-xl-1)+s.substr(xr+1));
		return foo1(s.substr(0,xl)+foo2(s.substr(xl+1,xr-xl-1))+s.substr(xr+1));
	}
	return foo2(s);
}

string solve(string s){
	return foo1(s);
}

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		// cout<<s.substr(0,0)<<endl;
		s=s.substr(0,s.size()-1);
		s=solve(s);
		cout<<s<<endl;
	}
}