WRP - WA,RTE and Placements

no tags 

The Placement Season has started at the Aliens’ College of Machine Learning (ACM) and as expected, every alien of the college is burning the candle at both ends. William Archer (WA), the topper and the most eligible bachelor of ACM is however indifferent towards the situation. He has been spending all his time with his friend Rihanna the Exuberant(RTE) and ignoring his studies. RTE, being the more mature and sensible of the two, devises a plan for WA so that he could spend adequate time with her without compromising his studies. Upon consultation with her best friend AC, she comes up with the following plan for WA:

  1. She divides WA's next N hours into K sessions.
  2. Each session can last for x hours where x is an integer and 1 <= x <= M.
  3. In each session, WA can either study or meet RTE.
  4. If WA is studying in one session, he must meet RTE in the next session and vice versa.
  5. WA must always study in the first session.

You have been hired by WA to calculate how many different timelines can RTE prepare for the next N hours.

Input

The first line specifies the number of test cases T and the next T lines contain 3 integers each: N, K and M.

Output

For every test case print a single integer which is the number of different ways RTE can prepare WA's timeline for the next N hours. Print your answer modulo 1000000007.

Constraints

T <= 100
1 <= N, K, M <= 100000
K <=N

Example

Input:
3
4 3 2
7 4 3
1 1 1

Output:
3
16
1

Explanation for Sample Input 1

RTE can prepare the following three schedules for the next 4 hours

S | MM | S
SS | M | S
S | M | SS

where S indicates that WA should be studying that hour, and M indicates that he should be meeting RTE that hour.

Note that WA has to start with his studies always in order to satisfy Point 5 of the plan.


hide comments
Jakub £opuszañski: 2021-01-02 18:54:44

This is a really beautiful combinatorics problem! I've actually learned something new about approaching problems like this one, thank you :)
BTW. Don't waste time on FFT - at least mine implementation of FFT timed out on this problem.

S.Y.P.Lai: 2014-09-08 15:52:18

I got WA, but I don't know why.

What should I print for the following cases:
- K x M < N
- K > N

Is there any special format I must use for modulo 1000000007 ? Should I print negative modular number?

EDIT: OK I finally fixed all the bugs. Next step is to make it 0.00 like others do.

NEW QUESTION: Why I got WA when I used int to store the input M. M should be less than 100000, right?

EDIT: OK. I know why. That's because my code checks K*M >= N and K*M needs 64 bit operation.

Last edit: 2014-09-09 08:21:24
Shaktiman: 2014-08-20 08:02:55

O(N*K) won't work.


Added by:utk1369
Date:2014-08-14
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Based on UVA-10721 but with larger constraints