
#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

