Sequence and Transformation

Count length-n sequences with entries in [1,m] whose image after applying a min-based affine transformation k times has the given max-minus-min value.

Hard9CombinatoricsMathDynamic programmingImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

A transformation is applied to a sequence a1,a2,,ana_1, a_2, \ldots, a_n of length nn. The transformation has two steps. First, build a new sequence b1,b2,,bnb_1, b_2, \ldots, b_n with the formula below.

bi=(minj=1naj)ai+j=1naj(1in)b_i = \left(\min_{j=1}^{n} a_j\right) - a_i + \sum_{j=1}^{n} a_j \quad (1 \le i \le n)

Then replace the sequence aa with the sequence bb, so aia_i takes the value bib_i for every 1in1 \le i \le n.

For a sequence xx of length nn, define q(x)=maxi=1nximini=1nxiq(x) = \max_{i=1}^{n} x_i - \min_{i=1}^{n} x_i.

The sequence rr is the result of applying the transformation kk times to some sequence, and you are given the value q(r)q(r) together with kk. Write a program that counts the sequences c1,c2,,cnc_1, c_2, \ldots, c_n satisfying both conditions below.

  1. 1cim1 \le c_i \le m for every 1in1 \le i \le n.
  2. q(d)=q(r)q(d) = q(r), where dd is the sequence obtained by applying the transformation kk times to the sequence cc.

Input

The first line contains the number of test cases TT (1T100001 \le T \le 10000).

Each test case is one line with four integers nn, mm, q(r)q(r), kk separated by spaces (1n,m,q(r),k1091 \le n, m, q(r), k \le 10^9).

Output

For each test case, print the answer modulo 109+710^9 + 7 on its own line.