LARGE - Large party

Irena and Sirup are organizing their engagement party next weekend. They want to invite almost everybody. They have just bought a very big round table for this occasion. But they are now wondering how should they distribute people around the table. Irena claimed that when there are more than K women next to each other, this group will chat together for the whole night and won't talk to anybody else.

Sirup had no other choice but to agree with her. However, being a mathematician, he quickly became fascinated by all the possible patterns of men and women around the table.

Problem specification

There will be N people sitting at the round table. Some of them will be men and the rest will be women.

Your task is to count in how many ways it is possible to assign the places to men and women in such a way that there will not be more than K women sitting next to each other.

If one assignment can be made from another one by rotating all the people around the table, we consider them equal (and thus count this assignment only once).

Input specification

The first line of the input file contains an integer T specifying the number of test cases. Each test case is preceded by a blank line.

The input for each test case consists of a single line that contains the two integers N(1<= N <1000) and K.

Output specification

For each test case output a single line with one integer – the number of ways how to distribute people around the table, modulo 100000007.

Example

input:
3

3 1

3 3

4 1

output:
2
4
3
Hint:

In the first test case there are two possibilities: MMM or MMW (M is a man, W is a woman).

In the second test case there are two more possibilities: MWW and WWW.

In the third test case the three possibilities are: MMMM, MMMW, and MWMW.

A Note: There are almost 1000 test cases, most of which are randomly generated (huge) ones.


Added by:Fudan University Problem Setters
Date:2008-05-24
Time limit:2s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: C99 ERL JS-RHINO OBJC SQLITE
Resource:IPSC 2008

hide comments
2011-03-15 01:54:55 S
Are the clockwise and anti-clockwise orders different?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.