This page is still under construction.

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

And

Time limit2sMemory limit512 MB

Summary
Count K-term non-negative integer sequences whose bitwise AND decreases monotonically and whose terms sum to N, modulo 1e9+7.
Level

Medium7 of 10

Topics
Bit manipulation, Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

Two integers NN and KK are given. Your task is to find the number of sequences with KK terms. A sequence must satisfy the following conditions.

  • A1+A2+A3+⋯+AK=NA_1 + A_2 + A_3 + \cdots + A_K = N
  • Ai+1=Ai & Ai+1A_{i+1} = A_i \, \& \, A_{i+1} (bitwise AND), i=1,2,…,K−1i = 1, 2, \ldots, K-1

Input

The first line gives a single positive integer TT, the number of test cases. (0≤T≤10)(0 \le T \le 10)

Each of the next TT lines gives two positive integers KK (0≤K≤105)(0 \le K \le 10^5) and NN (0≤N≤104)(0 \le N \le 10^4).

Output

Print the answer for each test case on one line. The answer can be very large, so print it modulo 109+710^9+7.

Examples1

  1. Example 1

    Input
    2
    2 3
    2 5
    
    Expected output
    1
    2