var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
    input += chunk;
});
process.stdin.on('end', function() {
    input = input.split('\n');
    main();
});

function main() {
    var
    i,
    n = +input[0],
    lines = input.slice(1);
    for(i = 0; i < n; i++) {
        console.log(calc(lines[i]));
    }
}

function calc(src) {
    var
    v, n,
    op = {'+': 1,'-': 1,'*': 2,'/': 2},
    ns = [],
    os = [];
    src = src.replace(/([-+*\/=()])/g, ' $1 ').split(' ');
    while((v = src.shift()) !== '=') {// console.log(v || ' ', ns, os);
        if(!v) continue;
	n = parseInt(v, 10);
        debugger;
	if(isNaN(n)) {
            if(op[v] && os.length && op[v] < op[os[0]]) {
                ns.push(oeval(os.shift(), ns.pop(), ns.pop()));
            }
	    if(op[v] || v === '(') {
	        os.unshift(v);
	    }
	    if(v === ')') {
                while((v = os.shift()) !== '(') {
                    ns.push(oeval(v, ns.pop(), ns.pop()));
	        }
	    }
        } else {
	    ns.push(n);
	}
    }
    while((v = os.shift()) !== undefined) {
	ns.push(oeval(v, ns.pop(), ns.pop()));
    }
    return ns[0];

    function oeval(op, b, a) {
	switch(op) {
	    case '+':
		return a + b;
            case '-':
		return a - b;
            case '*':
		return a * b;
            case '/':
		return Math.floor(a / b);
	}
    }
}