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) {
    src = src.replace(/([-+*\/()=])/g, ' $1 ').split(' ').filter(function(s) {
        return s.trim() !== '';
    });
    return add();

    function add() {
        var
        ret = mul(src);
        while(src[0] in {'+': 1,'-': 1}) {
            switch(src.shift()) {
            case '+':
                ret += mul(src);
                break;
            case '-':
                ret -= mul(src);
                break;
            }
        }
        return ret;
    }

    function mul() {
        var
        ret = prim(src);
        while(src[0] in {'*': 1,'/': 1}) {
            switch(src.shift()) {
            case '*':
                ret *= prim(src);
                break;
            case '/':
                ret = Math.floor(ret / prim(src));
                break;
            }
        }
        return ret;
    }

    function prim() {
        var
        ret, 
        head = src.shift();
        switch(head) {
        case '+':
           return prim(src);
        case '-':
           return -prim(src);
        case '(':
           ret = add(src);
           src.shift();
           return ret;
        default:
           return parseInt(head, 10);
        }
    }
}