#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <cctype>
using namespace std;

typedef string::iterator State;
int n;
string str;

int factor(State &begin);
int number(State &begin);
int term(State &begin);
int expressin(State &begin);

int factor(State &begin)
{
	int ret;
	if (*begin == '(')
	{
		begin++;
		ret = expressin(begin);
		begin++;
	}
	else
	{
		ret = number(begin);
	}
	return ret;
}

int number(State &begin)
{
	int ret = 0;
	while (isdigit(*begin))
	{
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}
	return ret;
}

int term(State &begin)
{
	int ret = factor(begin);
	while (true)
	{
		if (*begin == '*')
		{
			begin++;
			ret *= factor(begin);
		}
		else if (*begin == '/')
		{
			begin++;
			ret /= factor(begin);
		}
		else
		{
			break;
		}
	}

	return ret;
}

int expressin(State &begin)
{
	int ret = term(begin);
	while (true)
	{
		if (*begin == '+')
		{
			begin++;
			ret += term(begin);
		}
		else if (*begin == '-')
		{
			begin++;
			ret -= term(begin);
		}
		else
		{
			break;
		}
	}

	return ret;
}


int main()
{
	cin >> n;
	while (n--)
	{
		cin >> str;
		cout << expressin(str.begin()) << endl;
	}

	return 0;
}