#include <cassert>
#include <cctype>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;
string S = "";
int cur;
int digit(){
	assert(isdigit(S[cur]));
	int n = S[cur] - '0';
	cur = cur+1;
	return n;
}
int number(){
	int n = digit();
	while(cur < S.size() && isdigit(S[cur]))
		n = n*10 + digit();
	return n;
}
int factor();

int term(){
	int a = factor();
	while(cur < S.size() && (S[cur] == '*' || S[cur] == '/')){
		char op = S[cur++];
		int b = factor();
		if(op == '*'){
			a *= b;
		}else{
			a /= b;
		}
	}
	return a;
}

int expression(){
	int sum = term();
	while (cur < S.size() && (S[cur] == '+' || S[cur] == '-')){
		char op = S[cur];
		cur++;
		int b = term();
		if(op == '+'){
			sum += b;
		}else{
			sum -= b;
		}
	}
	return sum;
}

int factor(){
	if(S[cur] != '('){
		return number();
	}
	cur += 1;
	int n = expression();
	assert(S[cur] == ')');
	cur += 1;
	return n;
}

int main(){
	int N;
	cin >> N;
	for(int i = 0;i<N;i++){
		cur = 0;
		cin >> S;
		S.erase(S.size()-1);
		cout << expression() << endl;
	}
}