Binary Strings

Count binary strings whose length lies in [L, R], is a multiple of K, and contains no two adjacent 1s, modulo 1e9+7.

Hard8MathCombinatoricsDynamic programmingMatrixNo attempts yetTime limit1sMemory limit512 MB

Problem

A string made of only 0s and 1s is called a binary string. A boy became interested in binary strings that never place two 1s side by side. At first he counted how many such strings there are for a fixed length.

After solving that, he added more conditions. He now wants the number of binary strings that satisfy all three of the following.

  • The length of the string is between LL and RR, inclusive (1LR10181 \le L \le R \le 10^{18}).
  • The length of the string is a multiple of an integer KK (3K1093 \le K \le 10^9).
  • No two 1s appear consecutively in the string.

The count can be very large, so print it modulo 1,000,000,007.

Input

The first line contains the number of test cases TT (1T100001 \le T \le 10\,000).

Each of the next TT lines contains three integers LL, RR and KK, separated by spaces.

Output

For each test case, print one line in the form Case x: y. Here xx is the test case number starting from 1, and yy is the number of binary strings that satisfy the conditions, modulo 1,000,000,007.

Hint

For L=1L = 1, R=10R = 10 and K=3K = 3, only the lengths 3, 6 and 9 are counted. Strings that satisfy the conditions include 101, 000, 010, 101001 and 000010000.