Under construction

Still being built. Things may change

Cutting the Long Cake

Interview

Time limit2sMemory limit512 MB

Summary
Count the ways to make k-1 cuts in a cake of n cells so that every piece has the same number of toppings, modulo 1e9+7.
Level

Medium5 of 10

Topics
Combinatorics, Math, Array
Solved
No attempts yet

Problem

Albert baked a long cake of length nn. The cake is divided in advance into nn cells so that it can be split into nn equal parts, and some cells have fruit toppings.

For example, the figure below shows a cake with n=8n = 8, where 00 is a cell without a topping and 11 is a cell with a fruit topping. As an integer array, this is A=[0,1,1,0,0,1,1,0]A = [0, 1, 1, 0, 0, 1, 1, 0]. A[i]A[i] is 11 if the ii-th cell has a topping and 00 if it does not.

Albert wants to cut this cake exactly k−1k-1 times to make kk pieces. The cuts must satisfy the following conditions.

  • Condition 1: Every cake piece must contain the same number of cells with toppings.
  • Condition 2: No cell or piece may be discarded.

For example, when k=2k = 2, there are 77 ways to cut the cake above without discarding any cell or piece. Three of them satisfy condition 1. Each piece has two cells with toppings in these ways.

As another example, the figure below shows two ways to cut a cake with n=5n = 5, A=[0,1,0,1,0]A = [0, 1, 0, 1, 0], and k=2k = 2 that satisfy both conditions.

Given nn, kk, and the array AA that shows whether each cell has a topping, count the number of ways to cut the cake that satisfy the conditions. The answer can be very large, so print it modulo 109+710^9+7.

Input

The first line contains the number of test cases TT.

Each test case is given in two lines. The first line contains nn and kk separated by a space. The second line contains the array AA as a string of length nn with no spaces.

Output

Print the answer for each test case on its own line.

Constraints

  • 1≤T≤101 \le T \le 10
  • 1≤k≤n≤1 000 0001 \le k \le n \le 1\,000\,000

Examples1

  1. Example 1

    Input
    9
    1 1
    1
    5 1
    01010
    5 2
    01010
    5 3
    01010
    8 2
    01100110
    14 2
    00100100100100
    13 3
    0111010100100
    61 21
    1001001001001001001001001001001001001001001001001001001001001
    3 2
    000
    
    Expected output
    1
    1
    2
    0
    3
    3
    2
    486784380
    2