Under construction

Still being built. Things may change

Program

Interview

Time limit1sMemory limit128 MB

Summary
Count the starting values from 1 to M that reach exactly A after running the given add, subtract, multiply, and floor-divide program.
Level

Medium6 of 10

Topics
Binary search, Intervals, Simulation
Solved
No attempts yet

Problem

Hektor has recently started learning the programming language C--. A program in this language operates on a single natural-number variable that is stored in memory before any command is executed.

C-- provides the following commands:

  • += X : adds XX to the variable in memory.
  • -= X : subtracts XX from the variable in memory.
  • *= X : multiplies the variable in memory by XX.
  • /= X : divides the variable in memory by XX using integer division (rounding down).

Hektor wrote a C-- program and wants the value of the variable in memory to be exactly AA after the program finishes. How many initial values in the range [1,M][1, M] make this possible?

Input

The first line contains the number of test cases ZZ (1≤Z≤101 \le Z \le 10).

The first line of each test case contains the integers NN, MM, and AA (1≤N≤10001 \le N \le 1000, 1≤M≤10181 \le M \le 10^{18}, 0≤A≤10180 \le A \le 10^{18}). The next NN lines contain the commands of the program in order, where each XX satisfies 1≤X≤10181 \le X \le 10^{18}.

You may assume that after every command the variable always stays within the signed 64-bit integer range and never becomes negative.

Output

For each test case, print on its own line how many initial values satisfy the condition described above.

Examples4

  1. Example 1

    Input
    2
    1 6 1
    /= 3
    2 10 4
    += 2
    *= 3
    
    Expected output
    3
    0
    
  2. Example 2

    Input
    1
    1 10 7
    += 3
    
    Expected output
    1
    
  3. Example 3

    Input
    1
    1 100 15
    *= 5
    
    Expected output
    1
    
  4. Example 4

    Input
    1
    1 20 2
    /= 4
    
    Expected output
    4