import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;


string[] operators = ["=","(", ")", "+", "-", "*", "/"];
bool isOperator(string s) {
	return operators.canFind(s);
}
int priority(string op) {
	int i = 0;
	while(operators[i] != op)
		++i;
	return (i+1)/2;
}

string nextToken(ref string s) {
	string t = "";
	while(s[0].isDigit()) {
		t ~= s[0];
		s.popFrontN(1);
	}
	if(t == "") {
		t ~= s[0];
		s.popFrontN(1);
	}
	return t;
}

int apply(string op, int l, int r) {
	switch(op){
		case "+":
			return l+r;
		case "-":
			return l-r;
		case "*":
			return l*r;
		case "/":
			return l/r;
		default:
			return 0;
	}
}

void apply(string op, ref int[] vstack) {
	auto r = vstack.back;
	vstack.popBackN(1);
	auto l = vstack.back;
	vstack.popBackN(1);
	vstack ~= apply(op, l, r);
}

int calc(string s) {
	int[] vstack;
	string[] opstack;
	while(!s.empty()) {
		auto t = nextToken(s);
		if(!t.isOperator()) {
			vstack ~= to!int(t);
		} else {
			if(opstack.empty || t == "(" || t.priority() > opstack.back.priority())
				opstack ~= t;
			else {
				auto op = opstack.back;
				opstack.popBackN(1);
				if(op == "(") {
					continue;
				}
				apply(op, vstack);
				s = t~s;
			}
		}
	}
	return vstack.front;
}
void main() {
	int n = to!int(readln().strip());
	foreach(i; 0..n) {
		auto s = readln().strip();
		writeln(calc(s));
	}
}