#include <bits/stdc++.h>

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

string str;
int expr(int &idx);
int factor(int &idx);
int primary(int &idx);
int inum(int &idx);

// expr ::= factor | expr '+' factor | expr '-' factor
int expr(int &idx){
	auto ret = factor(idx);
	while(str[idx] != ')' && str[idx] != '='){
		auto op = str[idx];
		auto rest = factor(++idx);
		if(op == '+'){
			ret += rest;
		}
		else if(op == '-'){
			ret -= rest;
		}
		else{
//			cerr << op << endl;
			assert(0);
		}
	}
	return ret;
}


// factor ::= primary | factor '*' primary | factor '/' primary
int factor(int &idx){
	auto ret = primary(idx);
	while(str[idx] == '*' || str[idx] == '/'){
		auto op = str[idx];
		auto rest = primary(++idx);
		if(op == '*') ret *= rest;
		else if(op == '/') ret /= rest;
		else{
//			cerr << op << endl;
			assert(0);
		}
	}
	return ret;
}

// primary ::= '(' expr ')' | num
int primary(int &idx){
	int ret;
//	cerr << idx << ":" << str[idx] << endl;
	if(str[idx] == '('){
		ret = expr(++idx);
		assert(str[idx] == ')');
		idx++;
		return ret;
	}
	if(isdigit(str[idx])){
		return inum(idx);
	}
	assert(0);
	return -1;
}

int inum(int &idx){
	assert(isdigit(str[idx]));
	int i = idx;
	while(isdigit(str[idx]))idx++;
	return stoi(str.substr(i,idx-i));
}

signed main(){
	int n; cin >> n;
	for(int i = 0; i < n; i++){
		cin >> str;
		int idx =0 ;
		cout << expr(idx) << endl;
	}

	return 0;
}


