Number Sets (Large)

Count the remaining groups after merging interval numbers that share a prime factor of at least P.

Medium7Union-findNumber theoryNo attempts yetTime limit5sMemory limit512 MB

Problem

A block of consecutive integers is split into sets by the procedure below.

You are given the interval of integers to work on and an integer PP. At the start, every integer in the interval belongs to a separate set that holds only that integer. Then, for every pair of integers in the interval, if the two integers have a common prime factor that is at least PP, the two sets holding them are merged into one set.

How many sets are there when the procedure ends?

Input

The first line contains the number of test cases CC.

Each test case is one line with three integers AA, BB, PP separated by spaces. AA and BB are the first and the last integer of the interval, and PP is the number described above.

Constraints

  • 1C1001 \le C \le 100
  • 1AB10121 \le A \le B \le 10^{12}
  • BA+1000000B \le A + 1000000
  • 2PB2 \le P \le B

Output

For each test case, print one line of the form Case #X: Y, where XX is the test case number starting from 1 and YY is the number of sets.