#include <bits/stdc++.h>
using namespace std;

template<typename T>
struct Parser {
	using itr = string::const_iterator;
	itr now;
	T ans;
	const struct ex {
		vector<char> _012;
		ex() {
			_012.resize(10);
			for(int i = 0; i < 10; ++i) {
				_012[i] = (char)('0' + i);
			}
		}
	} ex;
	Parser(const string &s) {
		now = s.begin();
		ans = expr(now);
	}
	T expr(itr &now) {
		T ret = term(now);
		while(true) {
			if(*now == '+') {
				next(now, '+');
				ret += term(now);
			}else if(*now == '-') {
				next(now, '-');
				ret -= term(now);
			} else {
				return ret;
			}
		}
	}
	T term(itr &now) {
		T ret = fact(now);
		while(true) {
			if(*now == '*') {
				next(now, '*');
				ret *= fact(now);
			}else if(*now == '/') {
				next(now, '/');
				ret /= fact(now);
			} else {
				return ret;
			}
		}
	}
	T fact(itr &now) {
		if(*now == '(') {
			next(now, '(');
			T ret = expr(now);
			next(now, ')');
			return ret;
		} else {
			return numb(now);
		}
	}
	T numb(itr &now) {
		T ret = 0;
		while('0' <= *now and *now <= '9') {
			ret *= 10;
			ret += (T)(*now - '0');
			next(now, ex._012);
		}
		return ret;
	}
	void next(itr &now, const char expected) {
		vector<char> req = {expected};
		next(now, req);
	}
	void next(itr &now, const vector<char> &expected) {
		for(char c : expected) {
			if(*now == c) {
				now++;
				return;
			}
		}
		cerr << *now << "\n";
		for(char c : expected) cerr << c << "\n";
	}
};

int main() {
	int n; cin >> n;
	while(n--) {
		string s; cin >> s;
		Parser<int> parse(s);
		cout << parse.ans << "\n";
	}
	return 0;
}
