Calculator

No attempts yetTime limit1sMemory limit128 MB

Problem

The user feedback for your favourite open-source operating system is in, and the most requested feature turned out to be an extension of the built-in calculator. One of the suggested extensions is evaluating polynomials, and that is the part you are building.

You are given a polynomial that the user typed into the calculator together with a value for the variable. Evaluate the polynomial at that value.

Input

The first line contains TT, the number of polynomials. (0<T1000 < T \le 100)

Each test case consists of two lines. The first line contains an integer XX, the value of the variable the polynomial is evaluated at. (1000X1000-1000 \le X \le 1000)

The second line contains a polynomial PP whose coefficients are all integers. PP is a sum of terms of the form CXECX^E, where the coefficient CC and the exponent EE satisfy the following conditions.

  1. EE is an integer with 0E300 \le E \le 30. If EE is 0, then CXECX^E is written as CC. If EE is 1, then CXECX^E is written as CXCX, except when CC is 1 or -1, in which case it is written as XX or X-X.
  2. CC is an integer. If CC is 1 or -1 and EE is neither 0 nor 1, then CXECX^E is written as XEX^E or XE-X^E.
  3. A + sign is written only in front of a term whose CC is non-negative and which is not the first term of the polynomial.
  4. Exponents in consecutive terms are strictly decreasing.
  5. CC fits in a 32-bit signed integer.
  6. The value of each term CXECX^E also fits in a 32-bit signed integer.

A polynomial line contains no spaces.

Output

For each test case, print the value of the polynomial on its own line. If the value for test case ii is VV, print it as Case #i: V. Test cases are numbered from 1. The result fits in a 32-bit signed integer.