Limits 1s, 512 MB

In the mysterious Realm of Numericon, a group of ancient mathematicians discovered a unique pattern related to prime numbers. They found that to uncover the deepest secrets of Numericon, one must determine the largest xx such that mxm^x divides nCr^nC_r where n,rn, r and mm are integral parts of the mystery.

nCr=n!(nr)!  r!^nC_r =\frac{n!}{(n - r)!\space\cdot\space r!}

As the chosen one to unlock Numericon's secrets, you are tasked with creating a program to calculate the maximum value of xx for given n,rn, r and m.m. Can you unveil the hidden wisdom of Numericon and become the savior of this mystical land?

Input

The first line of the input contains an integer TT indicating the number of tests to be conducted.

Each of the following TT lines consists of three integers n,r,n, r, and mm separated by a space.

Constraints

  • 1T1031 ≤ T ≤ 10^3

  • 1n10181 ≤ n ≤ 10^{18}

  • 0rn0 ≤ r ≤ n

  • 2m10122 ≤ m ≤ 10^{12}

Output

You have to output TT lines in format “Case cc: xx”(without quotes) where cc is the test case number and xx is the result of the test case. Check out the samples for more clarification.

Sample

InputOutput
5
8 3 2
10 5 3
5 4 4
9 5 7
16 8 3
Case 1: 3
Case 2: 2
Case 3: 0
Case 4: 1
Case 5: 2

Explanation

  • Test 1:1: For n=8,r=3n = 8, r = 3 and m=2,m = 2, we have 8C3=56.^8C_3 = 56. Here largest 23=82^3 = 8 that divides 56,56, so xx is 3.3.

  • Test 2:2: For n=10,r=5n = 10, r = 5 and m=3,m = 3, we have 10C5=252.^{10}C_5 = 252. Here largest 32=93^2 = 9 that divides 252,252, so xx is 2.2.

  • Test 3:3: For n=5,r=4n = 5, r = 4 and m=4,m = 4, we have 5C4=5.^5C_4 = 5. Here largest 40=14^0 = 1 that divides 5,5, so xx is 0.0.


Be careful about the output formatting and newline (‘\n’) at the end.

Submit

Login to submit.

Statistics

0% Solution Ratio
Toph uses cookies. By continuing you agree to our Cookie Policy.