This page is still under construction.

Parts of this page are still being built. What you see may change.

The Return of the Tteokfire

Time limit1sMemory limit128 MB

Summary
Count sequences of M daily bowl counts summing to N, where the first M-1 counts are positive and the M-th is zero.
Level

Medium7 of 10

Topics
Combinatorics, Math, Dynamic programming
Solved
No attempts yet

Problem

A Tteokfire stays young by eating tteokguk, the Korean rice cake soup.

A Tteokfire ages one year for every bowl of tteokguk it eats. Digestion is instant, so it can eat as many bowls in one day as it likes. In exchange, a Tteokfire that goes a single day without tteokguk dies that day, no matter how much it ate before.

Didi knows only that one Tteokfire died on day MM at age NN. Didi wants to count how many ways that Tteokfire could have aged, but the count grows out of hand as the age rises, so counting by hand is hopeless.

A Tteokfire starts at age 0. One way of aging is the list of bowl counts for day 1 through day MM in order, and two ways are different when the count differs on at least one day. The Tteokfire ate nothing on day MM, which is why it died that day.

For NN equal to 3 and MM equal to 3 there are two ways: 1 bowl on day 1, 2 bowls on day 2 and 0 bowls on day 3, or 2 bowls on day 1, 1 bowl on day 2 and 0 bowls on day 3.

Input

The first line has the number of test cases TT (1≤T≤10001 \le T \le 1000).

Each of the next TT lines has two integers NN (0≤N≤1090 \le N \le 10^9) and MM (1≤M≤1091 \le M \le 10^9), separated by a space.

Output

For each test case, print the number of ways of aging modulo 100007 on its own line. Note that 100007 is not a modulus you see often.

Examples4

  1. Example 1

    Input
    1
    3 3
    
    Expected output
    2
    
  2. Example 2

    Input
    6
    5 3
    4 5
    2 5
    1 2
    10 6
    0 1
    
    Expected output
    4
    1
    0
    1
    126
    1
    
  3. Example 3

    Input
    5
    0 1
    0 2
    7 1
    1 1
    1000000000 2
    
    Expected output
    1
    0
    0
    0
    1
    
  4. Example 4

    Input
    6
    21 11
    20 11
    25 13
    24 12
    23 12
    22 12
    
    Expected output
    67953
    92378
    95976
    43989
    46604
    52695