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;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


vector<string> toRPN(string s){
    stack<string> ope;
    vector<string> ret;
    int len=s.size();
    
    for(int i=0;i<len;i++){
        if( isdigit(s[i]) ){
            string tmp="";
            for(int j=i;j<len;j++){
                if( isdigit(s[j]) )tmp+=s[j];
                else break;
            }
            ret.push_back(tmp);
            i+=tmp.size()-1;
            
        }else{
            if( s[i]=='(' )ope.push("(");
            
            else if( s[i]==')' ){
                if( ope.empty() )return {"invalid"};
                
                while( ope.top()!="(" ){
                    ret.push_back( ope.top() );
                    ope.pop();
                    
                    if( ope.empty() )return {"invalid"};
                }
                if( ope.empty() )return {"invalid"};
                ope.pop();
                
            }else if( s[i]=='*' || s[i]=='/' ){
                while( ope.size() && ( ope.top()=="*" || ope.top()=="/" ) ){
                    ret.push_back( ope.top() );
                    ope.pop();
                }
                ope.push( string(1,s[i]) );
                
            }else if( s[i]=='+' || s[i]=='-' ){
                while( ope.size() && ( ope.top()=="*" || ope.top()=="/" || ope.top()=="+" || ope.top()=="-" ) ){
                    ret.push_back( ope.top() );
                    ope.pop();
                }
                ope.push( string(1,s[i]) );
            }
        }
    }
    while( ope.size() ){
        ret.push_back( ope.top() );
        ope.pop();
    }
    
    return ret;
}




int solveRPN(vector<string> s){
    stack<int> stk;
    
    
    for(int i=0;i<s.size();i++){
        if( (s[i]!="+" && s[i]!="-" && s[i]!="*" && s[i]!="/") )stk.push( stoi(s[i])  );
        else{
            int b=stk.top(); stk.pop();
            int a=stk.top(); stk.pop();
            
            if(s[i]=="+")stk.push(a+b);
            if(s[i]=="-")stk.push(a-b);
            if(s[i]=="*")stk.push(a*b);
            if(s[i]=="/")stk.push(a/b);
        }
    }
    
    
    return stk.top();
}


int main(){
    int n;
    cin>>n;
    rep(i,n){
        string s;
        cin>>s;
        
        s.erase(s.size()-1);
        
        vector<string> poland;
        poland=toRPN(s);
        
//        rep(i,poland.size())cout<<poland[i];cout<<endl;
        
        int ans;
        ans=solveRPN(poland);
        
        cout<<ans<<endl;
    }
    
    return 0;
}

C++: 
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

std::string S;
size_t i = 0;
int32_t func();
int32_t getvalue()
{
	bool minus = false;
	if (S[i] == '-') {
		minus = true;
		++i;
	}
	int32_t nowv = 0;
	if (S[i] == '(') {
		++i;
		nowv = func();
	}
	else {
		while ('0' <= S[i] && S[i] <= '9') { nowv *= 10; nowv += S[i] - '0'; ++i; }
	}
	return nowv*(minus?-1:1);
}
int32_t func()
{
	int32_t tmpv = 0;
	int32_t tmpmulv = getvalue();
	while (S[i] != ')')
	{
		char ope = S[i];
		++i;
		int32_t nowv = getvalue();
		if (ope == '+') {
			tmpv += tmpmulv;
			tmpmulv = nowv;
		}
		else if (ope == '-') {
			tmpv += tmpmulv;
			tmpmulv = -nowv;
		}
		else if (ope == '*') {
			tmpmulv *= nowv;
		}
		else if (ope == '/') {
			tmpmulv /= nowv;
		}
	}
	++i;
	tmpv += tmpmulv;
	tmpmulv = 1;
	return tmpv;
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	int32_t Q;
	in >> Q;
	while (Q--)
	{
		in >> S;
		S.pop_back();
		S.push_back(')');
		i = 0;
		out << func() << endl;
	}

	return 0;
}
#endif

C++: #include "pch.h"
#include <iostream>
#include <string>
#include <cctype>
#include <vector>
using namespace std;

inline bool is_op(string &in) {
	if (in.size() == 1 && !isdigit(in[0]))
	{
		return true;
	}
	else
	{
		return false;
	}
}
inline bool is_num(string &in)
{
	for (auto i : in)
	{
		if (!isdigit(i))
			return false;
	}
	return true;
}
inline bool is_expr(string &in)
{
	if (!is_num(in) && !is_op(in)) { return true; }
	else { return false; }
}
vector<string> split(string in)
{
	vector<string> spl;
	int pos = 0;
	if (in[pos] == '-') 
	{
		pos++;
		while (pos < in.size()) {
			if (isdigit(in[pos])) {
				pos++;
			}
			else {
				break;
			}
		}
		spl.push_back(in.substr(0, pos));
		in.erase(0, pos);
		pos = 0;
	}
	while ( pos < in.size())
	{
		if (!isdigit(in[pos]))
		{
			if (pos != 0)
			{
				spl.push_back(in.substr(0, pos));
				in.erase(0, pos);
				pos = 0;
			}
			else
			{
				if (in[0] == '(')
				{
					int cnt = 1;
					int r_pos = 1;
					for (r_pos = 1; r_pos < in.size(); r_pos++)
					{
						if (in[r_pos] == '(')
							cnt++;
						if (in[r_pos] == ')')
							cnt--;
						if (cnt == 0)
							break;
					}
					spl.push_back(in.substr(pos + 1, r_pos - 0 - 1));
					in.erase(0, r_pos + 1);
					pos = 0;
					continue;
				}
				else if (in[0] == '+' || in[0] == '-' || in[0] == '*' || in[0] == '/')
				{
					spl.push_back(in.substr(0, 1));
					in.erase(0, 1);
					pos = 0;
				}
			}
		}
		else {
			pos++;
		}
	}
	if (in.size() != 0) spl.push_back(in);
	return spl;
}
int cal(string &in_str) {
	auto in = split(in_str);
	while (in.size() != 1) {
		auto pos = in.begin();
		while (pos != in.end()) 
		{
			if (*pos == "*") {
				pos--;
				*pos = to_string(cal(*pos)*cal(*(pos + 2)));
				in.erase(pos+1 , pos + 3);
			}
			else if (*pos == "/") {
				pos--;
				*pos = to_string(cal(*pos)/cal(*(pos + 2)));
				in.erase(pos+1, pos + 3);
			}
			if (in.size()==1) break;
			if (pos != in.end()) pos++;
		}
		pos = in.begin();
		while (pos != in.end()) {
			if (*pos == "+") {
				pos--;
				*pos = to_string(cal(*pos)+cal(*(pos + 2)));
				in.erase(pos+1, pos + 3);
			}
			else if (*pos == "-") {
				pos--;
				*pos = to_string(cal(*pos) - cal(*(pos + 2)));
				in.erase(pos+1, pos + 3);
			}
			if (in.size()==1) break;
			if(pos != in.end()) pos++;
		}
	}
	return(stoi(in[0]));
}
int main()
{
	/*string tmp = "(-2*2)*5+(1+2)*(3+4)";
	auto out=split(tmp);
	for (auto i : out) {
		cout << i << endl;
	}
	cout << cal(tmp) << endl;*/
	string input;
	int n;
	cin >> n;
	while (n--) {
		cin >> input;
		input.erase(input.end() - 1);
		cout << cal(input) << endl;
	}
	return 0;
}