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 C# (judge verdict: Accepted)

using System;

namespace _0109
{
	class Program
	{
		static string s;
		public static int pointer;
		static int number()
		{
			int ret = 0;
			while (pointer < s.Length && '0' <= s[pointer] && s[pointer] <= '9')
			{
				ret *= 10;
				ret += s[pointer] - '0';
				pointer++;
			}
			return ret;
		}
		static int term()
		{
			int ret = factor();
			while (pointer < s.Length)
			{
				if (s[pointer] == '*')
				{
					pointer++;
					ret *= factor();
				}
				else if (s[pointer] == '/')
				{
					pointer++;
					ret /= factor();
				}
				else break;
			}
			return ret;
		}
		static int expression()
		{
			int ret = term();
			while (pointer < s.Length)
			{
				if (s[pointer] == '+')
				{
					pointer++;
					ret += term();
				}
				else if (s[pointer] == '-')
				{
					pointer++;
					ret -= term();
				}
				else break;
			}
			return ret;
		}
		static int factor()
		{
			if (s[pointer] == '(')
			{
				pointer++;
				int ret = expression();
				pointer++;
				return ret;
			}
			else return number();
		}
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			for (int i = 0; i < n; i++)
			{
				s = Console.ReadLine();
				pointer = 0;
				Console.WriteLine(expression());
			}
		}
	}
}