DIVFIBS - Divisible Fibonacci Numbers

no tags 

In mathematics, the Fibonacci sequence is calculated by adding the previous two members of the sequence. The first few Fibonacci numbers are

1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...

Considering the indices start from 1 the 6th Fibonacci number in this sequence is 8 and is divisible by 1, 2, 4 and 8. You are given two indices L and R (L<=R) of this sequence and you have to calculate how many Fibonacci numbers are divisible by M in range [L, R] inclusive.

Input

Input begins with a line containing a single integer T (1<=T<=500), denoting the number of test cases. T test cases follow. Each test case begins with a line containing three integers L R (1<=L<=R<=100000) and M (1<=M<=1018)

Output

For each test case, output a single line containing the answer as an integer.

Example

Input:
3
6 6 4
4 18 5
1 10 3

Output:
1
3
2

hide comments
[Lakshman]: 2015-12-09 18:10:08

@imranziad can you please tell me for what kind of input I am getting wrong answer.

Prakhar Dev Gupta: 2015-12-09 10:24:24

Can I have more testcases? Getting WA but the three given test cases pass in DEV

Vipul Srivastava: 2015-12-08 19:40:16

@Lakshman: Yes you are right

[Lakshman]: 2015-12-08 19:29:31

I am not getting this problem You mean to say count
for(i=L;i<=R;i++) if fibonnaci[i]%m==0. ?


Added by:imranziad
Date:2015-12-08
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU JS-MONKEY