Hyperoperation Calculator

All submissions for this problem are available.
The Institute of Imaginary Mathematics (IIM) has drafted you to create a program that computes hyperoperations, two in particular, the Cotran function and the Xnad function. IIM defines the function as follows:
Cotran function:
a n b
if n = 0 then a n b: b + 3
if n = 1, b = 0 then a n b: a
if n = 2, b > 0 then a n b: a * b
if n = 3, b > 1 then a n b: a ^ b
otherwise a n b: (a  (n  1)  (a  (n  1)  (b  1)))
where a, b, n are integer values such that
mod(a) < 10^5
mod(b) < 10^5
n >= 0 && n <= 3
Xnad function:
a # b: a * b
a ## b: (a + 1) * b * (b  1)
a ### b: (a + 2) * (a + 1) * b * (b  1) * (b  2)
a #### b: (a + 3) * (a + 2) * (a + 1) * b * (b  1) * (b  2) * (b  3)
and so forth.
where a, b, n are integer values such that
mod(a) < 10^5
mod(b) < 10^5
IIM has also tasked that the calculator be able to cover basic addition and multiplication as well as parenthesis.
Input/Output Format:
IIM will provide input via stdin. The first input, N (N > 0 && N < 10) will specify the number of operations that follow. Each of the operations could either be a Cotran function, Xnad function, or basic addition/multiplication or a combination of any of those including parenthesis.
The output should be printed out to stdout, with each line as the result of each operation. So there should N lines in the output.
Example Input:
5
2 + 2
1 * 3
3 1 0
3 ## 2
3 ## (3 1 0)
Example Output:
4
3
3
8
24
Note: There is a newline character at the end of the output.
Explanation:
2 + 2 = 4
1 * 3 = 3
3 1 0 = 3
3 ## 2 = (3+1) * 2 * (21) = 4 * 2 * 1 = 8
3 ## (3 1 0) = 3 ## 3 = (3 + 1) * 3 * (3  1) = 4 * 3 * 2 = 24
Author:  maxmiaggi 
Tags  maxmiaggi 
Date Added:  21012016 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 