import std.stdio;
import std.array;
import std.string;
import std.conv;

void main(){
	int n;
	string s;
	readf("%d\n", &n);
	for (int i = 0; i < n; i++) {
		s = chomp(readln());
		s.popBack();
		writeln(expression(s));
	}
}

int expression(string s){
	for (int i = 0; i < s.length; i++) {
		if (s[i] == '(') {
			for (int j = i+1; j < s.length; j++) {
				if (s[j] == ')') {
					string tmp = to!string(expression(s[i+1..j]));
					s = replace(s, s[i..j+1], tmp);
				}
			}
		}
	}
	return factor(s);
}

int factor(string s){
	int start = 0;
	for (int i = 0; i < s.length; i++) {
		if (s[i] == '-' || s[i] == '+') start = i + 1;
		if (s[i] == '*' || s[i] == '/') {
			for (int j = i+1; j <= s.length; j++) {
				if (j == s.length || s[j] < '0' || s[j] > '9') {
					int tmp;
					if (s[i] == '*') tmp = to!int(s[start..i]) * to!int(s[i+1..j]);
					else if (s[i] == '/') tmp = to!int(s[start..i]) / to!int(s[i+1..j]);
					s = replace(s, s[start..j], to!string(tmp));
					i = start;
					break;
				}
			}
		}
	}
	return term(s);
}

int term(string s){
	for (int i = 0; i < s.length; i++) {
		if (s[i] == '-' || s[i] == '+') {
			for (int j = i+1; j <= s.length; j++) {
				if (j == s.length || s[j] < '0' || s[j] > '9') {
					int tmp;
					if (s[i] == '-') tmp = to!int(s[0..i]) - to!int(s[i+1..j]);
					else if (s[i] == '+') tmp = to!int(s[0..i]) + to!int(s[i+1..j]);
					s = replace(s, s[0..j], to!string(tmp));
					i = 0;
					break;
				}
			}
		}
	}
	return number(s);
}

int number(string s){
	return to!int(s);
}