Medium
Recursion > Parsing/Grammar

Yesterday, Jubaer was in IITLab-402 and writing a simple C code. Let’s have a look at his code-
#include <stdio.h>
int f(int a, int b) { return a + b; }
int g(int a, int b) { return a * b; }
int main(){
printf("%d\n”,f(g(2,3),5));
return 0;
}
When he wanted to run the code, electricity failure ruined it. He became very sad and I tried to make him understand that it’s not necessary to run a simple code while the result can be calculated by hand. He became angry and gave me hundreds of such codes. As I have a Laptop, can you please help me to calculate the outputs of such codes? You will be given only the function calling expression and you have to calculate the results.
Input:
------
Input starts with an Integer **T**, denoting the number of test cases. Each of next **T** lines contains a function calling expression. It is guaranteed that numbers are in range **[0,9]**. It is also guaranteed that there is no extra characters except ‘**f**’, ‘**g**’, ‘**(**‘, ‘**)**’, '**,**' and **digits** and output will always feet into a 32 bit signed integer.
Here, 1 <= **T** <= 20 and 1 <= **Length of expression** <= 500
Output:
-------
For each case print **Case X: Y**, where **X** is the case number and **Y** is the expected result. For invalid expression print **-1**.
Sample Input
------------
3
f(g(2,3),5)
f(4,f(g(2,3),f(5,3)))
f(2,5,8)
Sample Output
-------------
Case 1: 11
Case 2: 18
Case 3: -1

#### Please login to submit solution to this problem.