Problem:
Smart Calculator

Your task is to write a program which reads an expression and evaluates it.

The expression consists of numerical values, operators and parentheses, and the ends with '='.

The operators includes +, - , *, / where respectively represents, addition, subtraction, multiplication and division.

Precedence of the operators is based on usual laws. That is one should perform all multiplication and division first, then addition and subtraction. When two operators have the same precedence, they are applied from left to right.

You may assume that there is no division by zero.

All calculation is performed as integers, and after the decimal point should be truncated

Length of the expression will not exceed 100.

-1 × 109 ≤ intermediate results of computation ≤ 109

Input

The input is a sequence of datasets. The first line contains an integer n which represents the number of datasets. There will be n lines where each line contains an expression.

Output

For each datasets, prints the result of calculation.

Sample Input

2
4-2*3=
4*(8+4+3)=

Output for the Sample Input

-2
60

Solution in JavaScript (judge verdict: Wrong Answer)

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);
	}
    }
}