Under construction

Still being built. Things may change

Journey

Time limit2sMemory limit512 MB

Summary
Count binary strings of length N with no run of equal symbols longer than K, modulo 1e9+7.
Level

Medium6 of 10

Topics
Dynamic programming, Combinatorics, Math, Prefix sum
Solved
No attempts yet

Problem

One day, Homer was bored at home and decided to set out on a journey to discover the lands of Springfield. The lands of Springfield form an infinite grid. Homer's house is at cell (0,0)(0, 0), and his journey consists of NN steps, where each step is either a move one cell right or a move one cell down.

Already bored, Homer did not want his journey to be boring too. He decided he would not move in the same direction for more than KK consecutive steps. So a journey is interesting if, for every K+1K + 1 consecutive steps, Homer has moved in both directions.

Figure 1: Example with N=5N = 5 and K=2K = 2 (first test case)

Given NN and KK, count the interesting journeys Homer can make. Two journeys are different if, for some ii, the ii-th step of the first journey differs from the ii-th step of the second. The count can be large, so print it modulo 1 000 000 0071\,000\,000\,007.

Input

Your program is tested on one or more test cases. The first line of input holds a single integer TT, the number of test cases (1≤T≤5001 \le T \le 500), followed by TT test cases.

Each test case is given on a single line holding two integers separated by a single space. The first integer is the number of steps in Homer's journey, NN, and the second integer KK is the maximum number of consecutive steps Homer can take while moving in the same direction, where 0≤N≤1050 \le N \le 10^5 and 0≤K≤1050 \le K \le 10^5.

Output

For each test case, print on a single line the number of different journeys Homer can make, modulo 1 000 000 0071\,000\,000\,007.

Examples1

  1. Example 1

    Input
    2
    5 2
    10 1
    
    Expected output
    16
    2