#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<queue>
using namespace std;

string Erase(string a, int b, int c,string e) {//b???????????????c??????????????§????¶????
	string d;
	for (int i = 0; i < b; i++) {
		d += a[i];
	}
	d += e;
	for (int i = c+1; i < a.length(); i++) {
		d += a[i];
	}
	return d;
}
string kake(string a) {
	int b = 1; a = "*" + a;
	for (int c = 0; c < a.length(); c++) {
		int e = c+1;
		if (a[c] == '*') {
			string d;
			for (; e < a.length(); e++) {
				if (a[e] >= '0'&&a[e] <= '9')d += a[e];
				else break;
			}
			b *= stoi(d);
		}
		else if (a[c] == '/') {
			string d;
			for (; e < a.length(); e++) {
				if (a[e] >= '0'&&a[e] <= '9')d += a[e];
				else break;
			}
			b /= stoi(d);
		}
		c = e - 1;
	}
	return to_string(b);
}
string tasi(string a) {
	int b = 0; a = "+" + a;
	for (int c = 0; c < a.length(); c++) {
		int e = c + 1;
		if (a[c] == '+') {
			string d;
			for (; e < a.length(); e++) {
				if (a[e] >= '0'&&a[e] <= '9')d += a[e];
				else break;
			}
			b += stoi(d);
		}
		else if (a[c] == '-') {
			string d;
			for (; e < a.length(); e++) {
				if (a[e] >= '0'&&a[e] <= '9')d += a[e];
				else break;
			}
			b -= stoi(d);
		}
		c = e - 1;
	}
	return to_string(b);
}
string keisan(string a) {
	vector<string>V;
	string b;
	for (char c : a) {
		if (c == '+' || c == '-') {
			V.push_back(b);
			b = ""; b += c;
			V.push_back(b);
			b = "";
		}
		else b += c;
	}
	V.push_back(b);
	for (int i = 0; i < V.size(); i += 2) {
		V[i] = kake(V[i]);
	}
	string S;
	for (int i = 0; i < V.size(); i++) {
		S += V[i];
	}
	return tasi(S);
}
int main(){
	int a; cin >> a;
	for (int b = 0; b < a; b++) {
		string c; cin >> c;
		c = c.substr(0, c.length() - 1);
		c = "(" + c + ")";
		while (1) {
			bool s = false;//????????????????????? ( ?????????0
			int last = 0;
			for (int i = 0; i < c.length(); i++) {
				if (c[i] == '(') {
					s = false;
					last = i;
				}
				if (c[i] == ')') {
					if (!s) {
						c = Erase(c, last, i, keisan(c.substr(last+1,i-last-1)));
						break;
					}
					s = true;
				}
				if (i == c.length() - 1) { goto l; }
			}
		}
	l:;
		cout << c << endl;
	}
}