Grimmjow is not dead. He comes back to take revenge from Ichigo. This time, Grimmjow has a new release which gives a difficult mathematical question which is as follows. Given an odd prime number P, a non-negative integer K less than P, and positive integers U,V , find the number of ways of choosing a subset of (V * P) distinct numbers from the set {1, 2, 3, ..., (U * P)}, such that, the sum of these (V * P) numbers, when divided by P, leaves remainder K.  

Because his zanpakutou is useless here, Ichigo cannot do anything except to solve it. So, he asks you to solve it for him, so that, he can beat Grimmjow and rescue Orihime yet again. Since the answer can be large, output the number modulo (10^{9}+7).  

Input Format

Line 1: T  where T is the number of test cases. 

Lines 2 to T+1: U V K P 

U, V, K, P - As defined above.  

Output Format

A single integer on each line that denotes the number of ways to choose the subsets modulo (10^{9}+7).  

Constraints

1 ≤ T ≤ 5000 

1 ≤ V ≤ U 

( U * P ) ≤ 100000  

Sample Input

4
1 1 0 5
2 1 0 3
2 1 1 3
2 1 2 3

Sample Output

1
8
6
6

Explanation

In the first test case, we have to choose 5 numbers from {1, 2, 3, 4, 5} whose sum is divisible by 5. Only way to do this is to choose the set itself.

In the next three test cases, we have to choose 3 numbers from {1, 2, 3, 4, 5, 6}. There are 20 possible selections overall.  

The selections {1, 2, 3}, {1, 2, 6}, {1, 3, 5}, {1, 5, 6}, {2, 3, 4}, {2, 4, 6}, {3, 4, 5}, {4, 5, 6} are such that the sum of the chosen numbers leave remainder 0 when divided by 3.  

The selections {1, 2, 4}, {1, 3, 6}, {1, 4, 5}, {2, 3, 5}, {2, 5, 6}, {3, 4, 6} are such that the sum of the chosen numbers leave remainder 1 when divided by 3.  

The selections {1, 2, 5}, {1, 3, 4}, {1, 4, 6}, {2, 3, 6}, {2, 4, 5}, {3, 5, 6} are such that the sum of the chosen numbers leave remainder 2 when divided by 3.

Difficulty: MEDIUM
Tags: Combinatorics

Starter code:

Solutions:
(m, fac) = (10 ** 9 + 7, [1])
[fac.append(fac[-1] * i % m) for i in range(1, 100001)]

def comb(n, r):
	return fac[n] * pow(fac[r] * fac[n - r], m - 2, m) % m
for _ in range(int(input())):
	(u, v, k, p) = map(int, input().split())
	ret = (comb(u * p, v * p) - comb(u, v)) * pow(p, m - 2, m) % m
	if k == 0:
		ret += comb(u, v)
	print(ret % m)


(m, fac) = (10 ** 9 + 7, [1])
[fac.append(fac[-1] * i % m) for i in range(1, 100001)]

def comb(n, r):
	return fac[n] * pow(fac[r] * fac[n - r], m - 2, m) % m
for _ in range(int(input())):
	(u, v, k, p) = map(int, input().split())
	ret = (comb(u * p, v * p) - comb(u, v)) * pow(p, m - 2, m) % m
	if k == 0:
		ret += comb(u, v)
	print(ret % m)


(m, fac) = (10 ** 9 + 7, [1])
[fac.append(fac[-1] * i % m) for i in range(1, 100001)]

def comb(n, r):
	return fac[n] * pow(fac[r] * fac[n - r], m - 2, m) % m
for _ in range(int(input())):
	(u, v, k, p) = map(int, input().split())
	ret = (comb(u * p, v * p) - comb(u, v)) * pow(p, m - 2, m) % m
	if k == 0:
		ret += comb(u, v)
	print(ret % m)


(F, RP, M, M2) = ([1] * 100001, [None] * 100001, 10 ** 9 + 7, 10 ** 9 + 5)
for i in range(100000):
	F[i + 1] = (i + 1) * F[i] % M

def powM(b, e):
	return b if e == 1 else powM(b, e >> 1) ** 2 * b % M if e & 1 else powM(b, e >> 1) ** 2 % M

def C(n, m):
	if RP[m] == None:
		RP[m] = powM(F[m], M2)
	if RP[n - m] == None:
		RP[n - m] = powM(F[n - m], M2)
	return RP[m] * RP[n - m] % M * F[n] % M
for _ in range(int(input())):
	(U, V, K, P) = map(int, input().split(' '))
	cuv = C(U, V)
	print((((C(U * P, V * P) - cuv) * powM(P, M2) + (K == 0) * cuv) % M + M) % M)


(m, fac) = (10 ** 9 + 7, [1])
[fac.append(fac[-1] * i % m) for i in range(1, 100001)]

def comb(n, r):
	return fac[n] * pow(fac[r] * fac[n - r], m - 2, m) % m
for _ in range(int(input())):
	(u, v, k, p) = map(int, input().split())
	ret = (comb(u * p, v * p) - comb(u, v)) * pow(p, m - 2, m) % m
	if k == 0:
		ret += comb(u, v)
	print(ret % m)


mod = 1000000007
factlist = [1]
for i in range(1000000):
	factlist.append(factlist[-1] * (i + 1) % mod)
factinvlist = [0] * len(factlist)
factinvlist[-1] = pow(factlist[-1], mod - 2, mod)
for i in range(len(factlist) - 1, 0, -1):
	factinvlist[i - 1] = factinvlist[i] * i % mod

def choose(n, r):
	if n < r:
		return 0
	else:
		return factlist[n] * factinvlist[r] * factinvlist[n - r] % mod
t = int(input())
for _ in range(t):
	[u, v, k, p] = list(map(int, input().split()))
	toprint = ((choose(u * p, v * p) - choose(u, v)) * pow(p, mod - 2, mod) + (choose(u, v) if k == 0 else 0)) % mod
	print(toprint)


(m, fac) = (10 ** 9 + 7, [1])
[fac.append(fac[-1] * i % m) for i in range(1, 100001)]

def comb(n, r):
	return fac[n] * pow(fac[r] * fac[n - r], m - 2, m) % m
for _ in range(int(input())):
	(u, v, k, p) = map(int, input().split())
	ret = (comb(u * p, v * p) - comb(u, v)) * pow(p, m - 2, m) % m
	if k == 0:
		ret += comb(u, v)
	print(ret % m)


(m, fac) = (10 ** 9 + 7, [1])
[fac.append(fac[-1] * i % m) for i in range(1, 100001)]

def comb(n, r):
	return fac[n] * pow(fac[r] * fac[n - r], m - 2, m) % m
for _ in range(int(input())):
	(u, v, k, p) = map(int, input().split())
	ret = (comb(u * p, v * p) - comb(u, v)) * pow(p, m - 2, m) % m
	if k == 0:
		ret += comb(u, v)
	print(ret % m)


(m, fac) = (10 ** 9 + 7, [1])
[fac.append(fac[-1] * i % m) for i in range(1, 100001)]

def comb(n, r):
	return fac[n] * pow(fac[r] * fac[n - r], m - 2, m) % m
for _ in range(int(input())):
	(u, v, k, p) = map(int, input().split())
	ret = (comb(u * p, v * p) - comb(u, v)) * pow(p, m - 2, m) % m
	if k == 0:
		ret += comb(u, v)
	print(ret % m)