Heap

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

A dd-ary heap of size nn is an array a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n where for each pair of indices ii and jj such that 1in1 \le i \le n, 1jn1 \le j \le n and (i1)d+2jid+1(i - 1) \cdot d + 2 \le j \le i \cdot d + 1, the strict inequality a_j>a_ia\_j > a\_i holds. For example, for a ternary (d=3d = 3) heap of size 88, the required inequalities are: a_2>a_1a\_2 > a\_1, a_3>a_1a\_3 > a\_1, a_4>a_1a\_4 > a\_1, a_5>a_2a\_5 > a\_2, a_6>a_2a\_6 > a\_2, a_7>a_2a\_7 > a\_2, and a_8>a_3a\_8 > a\_3.

Consider all dd-ary heaps of size nn which also happen to be permutations of numbers from 11 to nn. Let us write them all down in lexicographical order comparing permutations as sequences of numbers. After that, we enumerate the heaps in the resulting ordered list starting from 11.

You are given a dd-ary heap of size nn which is also a permutation. Your task is to find the number of this heap in the ordered list constructed above. As the answer can be very large, compute it modulo (109+7)(10^9 + 7).

입력

The first line of input contains a positive integer TT: the number of test cases. The test cases follow.

Each test case is given on two lines. The first of these lines contains two integers nn and dd (1n30001 \le n \le 3000, 1d30001 \le d \le 3000). The second line contains nn integers describing the permutation. Each integer from 11 to nn occurs on that line exactly once. The given permutation is also a dd-ary heap.

The sum of all values of nn in the input does not exceed 30003000.

출력

For each test case, print the 11-based number of the given sequence in the lexicographically ordered list of dd-ary heaps which are also permutations, modulo (109+7)(10^9 + 7).