Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of $n$ different bloggers. Blogger numbered $i$ has $a_i$ followers.

Since Masha has a limited budget, she can only sign a contract with $k$ different bloggers. Of course, Masha wants her ad to be seen by as many people as possible. Therefore, she must hire bloggers with the maximum total number of followers.

Help her, find the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible. Two ways are considered different if there is at least one blogger in the first way, which is not in the second way. Masha believes that all bloggers have different followers (that is, there is no follower who would follow two different bloggers).

For example, if $n=4$, $k=3$, $a=[1, 3, 1, 2]$, then Masha has two ways to select $3$ bloggers with the maximum total number of followers:

conclude contracts with bloggers with numbers $1$, $2$ and $4$. In this case, the number of followers will be equal to $a_1 + a_2 + a_4 = 6$.

conclude contracts with bloggers with numbers $2$, $3$ and $4$. In this case, the number of followers will be equal to $a_2 + a_3 + a_4 = 6$.

Since the answer can be quite large, output it modulo $10^9+7$.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then $t$ test cases follow.

The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) — the number of bloggers and how many of them you can sign a contract with.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots a_n$ ($1 \le a_i \le n$) — the number of followers of each blogger.

It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.


-----Output-----

For each test case, on a separate line output one integer — the number of ways to select $k$ bloggers so that the total number of their followers is maximum possible.


-----Examples-----

Input
3
4 3
1 3 1 2
4 2
1 1 1 1
2 1
1 2
Output
2
6
1


-----Note-----

The test case is explained in the statements.

In the second test case, the following ways are valid:

conclude contracts with bloggers with numbers $1$ and $2$. In this case, the number of followers will be equal to $a_1 + a_2 = 2$;

conclude contracts with bloggers with numbers $1$ and $3$. In this case, the number of followers will be equal to $a_1 + a_3 = 2$;

conclude contracts with bloggers with numbers $1$ and $4$. In this case, the number of followers will be equal to $a_1 + a_4 = 2$;

conclude contracts with bloggers with numbers $2$ and $3$. In this case, the number of followers will be equal to $a_2 + a_3 = 2$;

conclude contracts with bloggers with numbers $2$ and $4$. In this case, the number of followers will be equal to $a_2 + a_4 = 2$;

conclude contracts with bloggers with numbers $3$ and $4$. In this case, the number of followers will be equal to $a_3 + a_4 = 2$.

In the third test case, the following ways are valid:

concludes a contract with a blogger with the number $2$. In this case, the number of followers will be equal to $a_2 = 2$.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Sorting

Combinatorics

Mathematics


Solutions:
import sys
import math

def fn(n, k, a):
	h = []
	a.sort(reverse=True)
	for i in range(k):
		h.append(a[i])
	h1 = h.count(min(h))
	h2 = a.count(min(h))
	p = 1
	for i in range(h1):
		p = p * (h2 - i)
	for i in range(h1):
		p = p // (h1 - i)
	return p % 1000000007
input = sys.stdin.read()
data = list(map(int, input.split()))
t = data[0]
l = 0
for i in range(t):
	n = data[l + 1]
	k = data[l + 2]
	a = data[l + 3:l + 3 + n]
	l = l + n + 2
	print(fn(n, k, a))


t = int(input())
from math import comb
for i in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	match = 0
	val = -1
	for j in range(k):
		if A[n - 1 - j] == val:
			match += 1
		else:
			match = 1
			val = A[-1 - j]
	math_2 = 0
	for j in range(n - k - 1, -1, -1):
		if A[j] == val:
			math_2 += 1
		else:
			break
	print(comb(match + math_2, match) % (10 ** 9 + 7))


from math import comb
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	for i in l:
		d[i] = d.get(i, 0) + 1
	l.sort()
	l.reverse()
	temp1 = l[:k]
	temp = set(temp1)
	ans = 1
	for i in temp:
		ans *= comb(d[i], temp1.count(i))
	print(ans % (10 ** 9 + 7))


f = [1] * 1001
fi = [1] * 1001
a = 1
m = 10 ** 9 + 7
for i in range(1, 1001):
	a *= i
	a %= m
	f[i] = a
b = pow(f[1000], m - 2, m)
fi[1000] = b
for i in range(999, 0, -1):
	fi[i] = b * (i + 1) % m
	b = fi[i]
for t in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	l1 = [0] * (n + 1)
	for i in l:
		l1[i] += 1
	a = l.index(l[k - 1])
	a = k - a
	print(f[l1[l[k - 1]]] * fi[l1[l[k - 1]] - a] * fi[a] % m)


import math
for i1 in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	lis = sorted([int(x) for x in input().split()])
	value = lis[-k]
	index = n - k
	last_index = n - lis[::-1].index(value) - 1
	first_index = lis.index(value)
	print(math.comb(last_index - first_index + 1, last_index - index + 1) % (10 ** 9 + 7))


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest
from copy import deepcopy
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

class Combination:

	def __init__(self, n_max, mod=10 ** 9 + 7):
		self.mod = mod
		self.modinv = self.make_modinv_list(n_max)
		(self.fac, self.facinv) = self.make_factorial_list(n_max)

	def __call__(self, n, r):
		return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

	def make_factorial_list(self, n):
		fac = [1]
		facinv = [1]
		for i in range(1, n + 1):
			fac.append(fac[i - 1] * i % self.mod)
			facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
		return (fac, facinv)

	def make_modinv_list(self, n):
		modinv = [0] * (n + 1)
		modinv[1] = 1
		for i in range(2, n + 1):
			modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
		return modinv
comb = Combination(3000)
for _ in range(inp()):
	(n, k) = inpl()
	a = inpl()
	a.sort(reverse=True)
	cnt = Counter(a)
	ln = 0
	for i in range(k):
		if a[i] == a[k - 1]:
			ln = k - i
			break
	print(comb(cnt[a[k - 1]], ln))


MOD = 1000 * 1000 * 1000 + 7
fact = [1] * 1005
inv = [1] * 1005

def fastexp(base, exp):
	if exp == 0:
		return 1
	temp = fastexp(base, exp // 2)
	temp = temp * temp % MOD
	if exp % 2 == 1:
		temp = temp * base % MOD
	return temp

def precompute():
	for i in range(1, 1001):
		fact[i] = fact[i - 1] * i % MOD
		inv[i] = fastexp(fact[i], MOD - 2)

def choose(n, r):
	return fact[n] * inv[r] % MOD * inv[n - r] % MOD

def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	nchoose = 0
	rchoose = 0
	for i in range(n):
		if a[i] == a[n - k]:
			nchoose += 1
			if i >= n - k:
				rchoose += 1
	print(choose(nchoose, rchoose))

def main():
	precompute()
	t = int(input())
	for i in range(t):
		solve()
main()


import math, sys, bisect, heapq, os
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
int1 = lambda x: int(x) - 1

def input():
	return sys.stdin.readline().rstrip('\r\n')
aj = lambda : list(map(int, input().split()))

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]
MOD = 1000000000 + 7

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])

def nCr(n, r):
	p = 10 ** 9 + 7
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def solve():
	for _ in range(int(input())):
		(n, k) = aj()
		A = aj()
		A.sort(reverse=True)
		b = A[:k]
		l = b[-1]
		c = A.count(l)
		r = b.count(l)
		print(nCr(c, r) % MOD)
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
solve()


fact = [1] * 1001
for i in range(1, 1001):
	fact[i] = fact[i - 1] * i
MOD = 10 ** 9 + 7

def solve():
	(n, k) = map(int, input().split())
	a = [int(s) for s in input().split()]
	a.sort(reverse=True)
	cnt = [0] * (n + 1)
	for i in a:
		cnt[i] += 1
	used = [0] * (n + 1)
	for i in range(k):
		used[a[i]] += 1
	id = -1
	for i in range(n + 1):
		if used[i] == 0 or used[i] == cnt[i]:
			continue
		if used[i] != cnt[i] and id == -1:
			id = i
		elif used[i] != cnt[i] and id != -1:
			exit(1)
	ans = 1
	if id != -1:
		N = cnt[id]
		K = used[id]
		ans *= fact[N] // (fact[K] * fact[N - K])
		ans %= MOD
	print(ans)

def main():
	for i in range(int(input())):
		solve()
main()


import math
for j in range(int(input())):
	(m, n) = map(int, input().split())
	l = [int(x) for x in input().split()]
	l.sort(reverse=True)
	a = l[n - 1]
	b = l.count(a)
	for p in range(n):
		if l[p] == a:
			break
	e = n - p
	ans = math.comb(b, e)
	print(ans % 1000000007)


from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
mod = 10 ** 9 + 7
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = sorted(map(int, input().split()))
	a = A[-k]
	bl = bsl(A, a)
	br = bsr(A, a)
	x = br - bl
	y = n - k - bl
	ans = 1
	if x < 2 * y:
		y = x - y
	for i in range(y):
		ans *= x - i
		ans *= pow(i + 1, -1, mod)
		ans %= mod
	print(ans)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
N = 10001
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)

def InverseofNumber(p):
	naturalNumInverse[0] = naturalNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		naturalNumInverse[i] = naturalNumInverse[p % i] * (p - int(p / i)) % p

def InverseofFactorial(p):
	factorialNumInverse[0] = factorialNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		factorialNumInverse[i] = naturalNumInverse[i] * factorialNumInverse[i - 1] % p

def factorial(p):
	fact[0] = 1
	for i in range(1, N + 1):
		fact[i] = fact[i - 1] * i % p

def Binomial(N, R, p):
	ans = fact[N] * factorialNumInverse[R] % p * factorialNumInverse[N - R] % p
	return ans
p = 1000000007
InverseofNumber(p)
InverseofFactorial(p)
factorial(p)
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort()
	c = [0] * n
	for i in range(n):
		c[arr[i] - 1] += 1
	a = [0] * n
	for i in range(k):
		a[arr[-i - 1] - 1] += 1
	ans = 1
	for i in range(n):
		if a[i] > 0:
			ans *= Binomial(c[i], a[i], p)
			ans %= p
	print(ans)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
for _ in range(int(inp())):
	(n, k) = mp()
	arr = lmp()
	arr.sort()
	ansl = arr[n - k:]
	x = ansl[0]
	a = arr.count(x)
	b = ansl.count(x)
	print(ncr(a, b, mod))


def factorial(number):
	if number <= 1:
		return 1
	fact = 1
	for i in range(1, number + 1):
		fact *= i
	return fact

def solution(array, k, n):
	N = 0
	R = 0
	array.sort()
	element = array[n - k]
	for i in range(n - k, n):
		if array[i] == element:
			R += 1
	for i in range(n):
		if array[i] == element:
			N += 1
	answer = factorial(N) // (factorial(R) * factorial(N - R))
	return answer % (1000000000 + 7)
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	array = list(map(int, input().split()))
	ans = solution(array, k, n)
	print(ans)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
import time
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]

def isInt(s):
	return '0' <= s[0] <= '9'
MOD = 10 ** 9 + 7
facs = [1]
curr = 1
for j in range(1, 1005):
	curr *= j
	curr %= MOD
	facs.append(curr)
inv_facs = []
for f in facs:
	inv_facs.append(pow(f, MOD - 2, MOD))

def ncr(n, k):
	return facs[n] * inv_facs[k] * inv_facs[n - k] % MOD

def solve():
	(N, K) = getInts()
	A = getInts()
	A.sort(reverse=True)
	ans = 0
	ind = K - 1
	while ind >= 0:
		if A[ind] == A[K - 1]:
			ind -= 1
		else:
			break
	ind2 = K - 1
	while ind2 < N:
		if A[ind2] == A[K - 1]:
			ind2 += 1
		else:
			break
	ind2 -= 1
	ind += 1
	n = ind2 - ind + 1
	k = K - ind
	return ncr(n, k)
for _ in range(getInt()):
	print(solve())


import sys
from math import gcd
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))

def ncr(n, r, md):
	p = 1
	k = 1
	r = min(n - r, r)
	m = k = 1
	while r:
		p *= n
		p //= m
		n -= 1
		r -= 1
		m += 1
	p %= md
	return p
(t,) = I()
for _ in range(t):
	(n, k) = I()
	l = sorted(I())
	x = l[n - k]
	(x, y) = (l.count(x), l[n - k:].count(x))
	md = 10 ** 9 + 7
	print(ncr(x, y, md))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())), reverse=True)
	x = a[k - 1]
	i = 0
	while a[i] != x:
		i += 1
		k -= 1
	n = a.count(x)
	r = k
	y = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
	print(y % 1000000007)


from math import comb
for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=1)
	n = a.count(a[k - 1])
	r = a[:k].count(a[k - 1])
	print(comb(n, r) % (10 ** 9 + 7))


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')

def C(n, r, mod):
	if r > n:
		return 0
	num = den = 1
	for i in range(r):
		num = num * (n - i) % mod
		den = den * (i + 1) % mod
	return num * pow(den, mod - 2, mod) % mod
tc = 1
(tc,) = inp()
for _ in range(tc):
	(n, k) = inp()
	a = inp()
	a.sort(reverse=True)
	b = a[:k]
	a1 = b.count(b[-1])
	a2 = a.count(b[-1])
	print(C(a2, a1, mod))


from collections import Counter
from math import comb

def advertising_agency(lst, k):
	s = set(lst)
	s = list(s)
	s.sort()
	s = s[::-1]
	d = Counter(lst)
	result = 1
	i = 0
	while k > 0:
		n = d[s[i]]
		if k >= n:
			k -= n
		else:
			result *= comb(n, k)
			k = 0
		i += 1
	return result % (10 ** 9 + 7)
n = int(input())
for i in range(n):
	input1 = [int(x) for x in input().split()]
	input2 = [int(x) for x in input().split()]
	print(advertising_agency(input2, input1[1]))


from math import comb
tc = int(input())
for _ in range(tc):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	val = arr[k - 1]
	objects = 0
	sample = 0
	for i in range(n):
		if arr[i] == val:
			if i < k:
				objects += 1
				sample += 1
			else:
				objects += 1
	ret = comb(objects, sample)
	print(ret % 1000000007)


from collections import Counter
T = int(input())
ans_ls = [0] * T

class Combination:

	def __init__(self, n, mod=10 ** 9 + 7):
		self.mod = mod
		self.fac = [1] * (n + 1)
		for i in range(1, n + 1):
			self.fac[i] = self.fac[i - 1] * i % self.mod
		self.invfac = [1] * (n + 1)
		self.invfac[n] = pow(self.fac[n], self.mod - 2, self.mod)
		for i in range(n - 1, 0, -1):
			self.invfac[i] = self.invfac[i + 1] * (i + 1) % self.mod

	def nCr(self, n, r, default_none=0):
		if n < r:
			return default_none
		return self.fac[n] * self.invfac[r] % self.mod * self.invfac[n - r] % self.mod

	def permutation(self, n, r, default_none=0):
		if n < r:
			return default_none
		return self.factorial(n) * self.invfactorial(n - r) % self.mod

	def factorial(self, i):
		return self.fac[i]

	def invfactorial(self, i):
		return self.invfac[i]
c = Combination(10 ** 3 + 10)
for t in range(T):
	(N, K) = map(int, input().split())
	a_ls = list(map(int, input().split()))
	a_ls.sort(reverse=True)
	selected = a_ls[:K]
	best_min = selected[-1]
	best_notmin_count = 0
	for i in range(K):
		if a_ls[i] != best_min:
			best_notmin_count += 1
	min_count_in_total = Counter(a_ls)[best_min]
	ans_ls[t] = c.nCr(min_count_in_total, K - best_notmin_count)
for ans in ans_ls:
	print(ans)


from math import factorial
n = int(input())
for k in range(n):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b.sort()
	temp = b[a[0] - a[1]:]
	not_chosen = b[:a[0] - a[1]]
	if not_chosen.count(b[a[0] - a[1]]) > 0:
		possible = temp.count(b[a[0] - a[1]]) + not_chosen.count(b[a[0] - a[1]])
		need = temp.count(b[a[0] - a[1]])
		x = factorial(possible) // factorial(possible - need)
		y = factorial(need)
		z = x // y
		print(z % 1000000007)
	else:
		print(1)


table = {}

def nCr(n, r):
	if (n, r) in table:
		return table[n, r]
	elif r == 0:
		return 1
	elif r == 1:
		return n
	elif n == r:
		return 1
	else:
		table[n, r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)) % 1000000007
		return table[n, r]

def main():
	T = int(input())
	for c in range(T):
		inp = input().rstrip().split(' ')
		(n, k) = (int(inp[0]), int(inp[1]))
		arr = input().rstrip().split(' ')
		hmap = {}
		for i in range(n):
			if int(arr[i]) not in hmap:
				hmap[int(arr[i])] = 0
			hmap[int(arr[i])] += 1
		arr = list(hmap.keys())
		arr.sort(reverse=True)
		m = 0
		i = 0
		while not m + hmap[arr[i]] >= k:
			m += hmap[arr[i]]
			i += 1
		print(nCr(hmap[arr[i]], k - m))
main()


from math import comb
for t in range(int(input())):
	(n, k) = map(int, input().split())
	l = [*map(int, input().split())]
	l.sort(reverse=True)
	d = {item: l.count(item) for item in l}
	move = l[k - 1]
	moc = 0
	for i in range(k - 1, -1, -1):
		if move == l[i]:
			moc += 1
		else:
			break
	ans = comb(d[move], moc)
	print(ans % 1000000007)


from math import comb
mod = int(1000000000.0 + 7)
t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	ji = [0] * 1005
	li = list(map(int, input().split()))
	for i in li:
		ji[i] += 1
	li.sort()
	dic = dict()
	st = set()
	for i in range(n - 1, n - k - 1, -1):
		st.add(li[i])
		dic[li[i]] = dic.setdefault(li[i], 0) + 1
	ans = 1
	for x in st:
		ans *= comb(ji[x], dic[x])
	ans %= mod
	print(ans)


from collections import Counter
import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	a.reverse()
	x = a[k - 1]
	i = 0
	while a[i] != x:
		i += 1
		k -= 1
	n = a.count(x)
	r = k
	y = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
	print(y % 1000000007)


import sys
from bisect import bisect_left
input = sys.stdin.readline

def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	if k == n or a[k - 1] != a[k]:
		print(1)
	else:
		z = a[k - 1]
		for j in range(k - 2, -1, -1):
			if a[j] != z:
				break
		else:
			j = -1
		for i in range(k, n):
			if a[i] != z:
				break
		else:
			i = n
		MOD = int(1000000000.0) + 7
		cnt = i - j
		ans = 1
		dd = 1
		for z in range(1, k - j):
			cnt -= 1
			ans = ans * cnt % MOD
			dd = dd * z % MOD
		print(ans * pow(dd, MOD - 2, MOD) % MOD)
for i in range(int(input())):
	solve()


def factorial(number):
	if number <= 1:
		return 1
	fact = 1
	for i in range(1, number + 1):
		fact *= i
	return fact

def solve(array, k, n):
	N = 0
	R = 0
	array.sort()
	element = array[n - k]
	for i in range(n - k, n):
		if array[i] == element:
			R += 1
	for i in range(n):
		if array[i] == element:
			N += 1
	answer = factorial(N) // (factorial(R) * factorial(N - R))
	print(answer % (1000000000 + 7))
	return
for test in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = solve(l, k, n)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def nCk(n, k):
	res = 1
	for i in range(1, k + 1):
		res = res * (n - i + 1) // i
	return res
from collections import Counter
for t in range(int(input())):
	(n, k) = map(int, input().split())
	arr = sorted(list(map(int, input().split())), reverse=True)
	ans = 1
	d1 = Counter(arr[:k])
	d2 = Counter(arr[k:])
	vis = [0] * 1001
	for i in range(k):
		if vis[arr[i]] == 0 and d2[arr[i]] >= 1:
			ans *= nCk(d1[arr[i]] + d2[arr[i]], d1[arr[i]])
			vis[arr[i]] = 1
	ans = max(ans, 1)
	print(ans % (10 ** 9 + 7))


def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
stdin = list(list(sys.stdin))
t = int(stdin[0].strip())
for i in range(t):
	inp = stdin[2 * i + 1].rstrip().split(' ')
	n = int(inp[0])
	k = int(inp[1])
	a = [int(i) for i in stdin[2 * i + 2].rstrip().split(' ')]
	a.sort(reverse=True)
	x = a[k - 1]
	start = a.index(x)
	print(ncr(a.count(x), k - start, 10 ** 9 + 7))


mod = int(1000000000.0 + 7)

def fact(x):
	ans = 1
	for i in range(2, x + 1):
		ans = ans * i % mod
	return ans

def C(x, k):
	return fact(x) * (pow(fact(k), mod - 2, mod) % mod) * (pow(fact(x - k), mod - 2, mod) % mod)

def solve():
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	arr = [0] * (n + 1)
	for i in input().split():
		x = int(i)
		arr[x] += 1
	for i in range(n, -1, -1):
		if arr[i] >= m:
			return int(C(arr[i], m) % mod)
		else:
			m -= arr[i]
	return 1
no_tests = int(input())
results = []
for i in range(no_tests):
	results.append(solve())
for result in results:
	print(result)


import collections, sys, functools, heapq, bisect
input = sys.stdin.readline
mod = 10 ** 9 + 7
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	a.sort()
	ans = 0
	y = bisect.bisect_right(a, a[-k])
	x = bisect.bisect_left(a, a[-k])
	num = y - x
	ele = y - (n - k)
	numerator = 1
	denominator = 1
	for i in range(ele):
		numerator *= num - i
		denominator *= i + 1
	ans = numerator // denominator % mod
	print(ans)


from sys import stdin
t = int(stdin.readline())
fact = [1]
for x in range(1, 1001):
	fact.append(x * fact[-1])

def C(a, b):
	return fact[b] // (fact[a] * fact[b - a]) % (10 ** 9 + 7)
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	arr = sorted(list(map(int, stdin.readline().split())), reverse=True)
	dct = {}
	minn = arr[k - 1]
	position1 = 0
	jump = n - 1
	while jump > 0:
		if position1 + jump >= n:
			jump = jump // 2
		elif arr[position1 + jump] <= minn:
			jump = jump // 2
		else:
			position1 += jump
	if arr[position1] > minn:
		position1 += 1
	position2 = 0
	jump = n - 1
	while jump > 0:
		if position2 + jump >= n:
			jump = jump // 2
		elif arr[position2 + jump] < minn:
			jump = jump // 2
		else:
			position2 += jump
	print(C(k - 1 - position1 + 1, position2 - position1 + 1))


from math import comb
t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	L = [int(x) for x in input().split()]
	count = [0] * (max(L) + 1)
	for x in L:
		count[x] += 1
	for x in reversed(count):
		if k - x > 0:
			k -= x
		else:
			print(comb(x, k) % 1000000007)
			break


import sys, math
inputs = sys.stdin.read().splitlines()
tc = int(inputs[0])
out = []
for i in range(tc):
	line = [int(i) for i in inputs[i * 2 + 1].split()]
	n = line[0]
	k = line[1]
	followers = [0 for i in range(n)]
	line = [int(i) for i in inputs[i * 2 + 2].split()]
	for val in line:
		followers[n - val] += 1
	for i in range(n):
		if followers[i] >= k:
			out.append(str(math.comb(followers[i], k) % 1000000007))
			break
		k -= followers[i]
sys.stdout.writelines('\n'.join(out))


from math import gcd
mod = int(1000000000.0) + 7

def ip(mode):
	if mode == 0:
		return int(input())
	if mode == 1:
		return list(map(int, input().split()))
	if mode == 2:
		return input()
	if mode == 3:
		return list(map(str, input().split()))
	if mode == 4:
		return map(int, input().split())
	if mode == 5:
		return map(str, input().split())

def printNcR(n, r):
	p = 1
	k = 1
	if n - r < r:
		r = n - r
	if r != 0:
		while r:
			p *= n
			k *= r
			m = gcd(p, k)
			p //= m
			k //= m
			n -= 1
			r -= 1
	else:
		p = 1
	return p
for _ in range(int(input())):
	(n, k) = ip(4)
	l = ip(1)
	l.sort(reverse=True)
	lo = k - 1
	hi = k - 1
	for i in range(k - 1, -1, -1):
		if l[i] == l[k - 1]:
			lo = i
		else:
			break
	for i in range(k, n):
		if l[i] == l[k - 1]:
			hi = i
		else:
			break
	r = k - lo
	num = hi - lo + 1
	ans = printNcR(num, r) % mod
	if ans < 0:
		ans += mod
	print(ans)


m = 10 ** 9 + 7
from math import comb

def solve(l, n, k):
	l.sort(reverse=True)
	c = l.count(l[k - 1])
	a = l.index(l[k - 1])
	r = k - a
	ans = comb(c, r)
	print(ans % m)
t = int(input())
while t:
	l = [int(i) for i in input().split(' ')]
	(n, k) = (l[0], l[1])
	l = [int(i) for i in input().split(' ')]
	solve(l, n, k)
	t -= 1


import math, sys
input = sys.stdin.readline
from collections import Counter

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res

def nCr(n, r):
	p = 10 ** 9 + 7
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	c = Counter(l)
	s = 1
	if c[l[k - 1]] > 1:
		s = nCr(c[l[k - 1]], k - l.index(l[k - 1]))
	print(int(s) % (10 ** 9 + 7))


from math import *
import sys
import collections
import bisect
import string

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def printNcR(n, r):
	p = 1
	k = 1
	if n - r < r:
		r = n - r
	if r != 0:
		while r:
			p *= n
			k *= r
			m = gcd(p, k)
			p //= m
			k //= m
			n -= 1
			r -= 1
	else:
		p = 1
	return p
for t in range(int(input())):
	(n, k) = map(int, input().split())
	arr = get_list()
	arr.sort(reverse=True)
	c = dict()
	for i in arr:
		if i in c:
			c[i] += 1
		else:
			c[i] = 1
	ans = 1
	for i in c:
		if k >= c[i]:
			k -= c[i]
		else:
			p = 1000000007
			val = printNcR(c[i], k)
			ans = ans * (val % (10 ** 9 + 7))
			break
	print(ans)


import math
n = int(input())
for _ in range(n):
	(a, b) = [int(i) for i in input().split()]
	c = [int(i) for i in input().split()]
	c = sorted(c, reverse=True)
	d = {}
	for i in range(0, len(c)):
		if c[i] not in d:
			d[c[i]] = 1
		else:
			d[c[i]] = d[c[i]] + 1
	e = {}
	for i in range(0, b):
		if c[i] not in e:
			e[c[i]] = 1
		else:
			e[c[i]] = e[c[i]] + 1
	ans = 1
	for (i, j) in e.items():
		fact = math.factorial(d[i]) // (math.factorial(d[i] - j) * math.factorial(j))
		ans = ans * fact
	print(ans % 1000000007)


from math import comb
MOD = 10 ** 9 + 7

def solve():
	[n, k] = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	a.sort(reverse=True)
	lo = 0
	hi = n - 1
	while lo < hi:
		mid = lo + (hi - lo) // 2
		if a[mid] > a[k - 1]:
			lo = mid + 1
		else:
			hi = mid
	l = lo
	hi = n
	while lo < hi:
		mid = lo + (hi - lo) // 2
		if a[mid] < a[k - 1]:
			hi = mid
		else:
			lo = mid + 1
	r = lo
	print(comb(r - l, k - l) % MOD)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


mod = 1000000007
t = int(input())
for i in range(t):
	[n, k] = [int(k) for k in input().split()]
	a = [int(k) for k in input().split()]
	a.sort(reverse=True)
	tot = 0
	no = 0
	for j in range(n):
		if a[j] == a[k - 1]:
			tot = tot + 1
			if j < k:
				no = no + 1
	ans = 1
	p = 1
	for j in range(tot, tot - no, -1):
		ans = ans * j
		ans = ans // p
		p = p + 1
	print(ans % mod)


import sys, os, io
import math, bisect, operator
(inf, mod) = (float('inf'), 10 ** 9 + 7)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
Neo = lambda : list(map(int, input().split()))
(test,) = Neo()
fact = [1]
for i in range(1, 1001):
	fact.append(fact[-1] * i % mod)
for _ in range(test):
	(n, m) = Neo()
	A = Neo()
	A.sort(reverse=True)
	c = Counter(A)
	d = Counter(A[:m])
	Ans = 1
	for i in d:
		k = c[i]
		r = d[i]
		Ans *= fact[k] * pow(fact[r] * fact[k - r] % mod, mod - 2, mod)
		Ans %= mod
	print(Ans % mod)


from math import factorial as f
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	a = l.count(l[k - 1])
	b = k - l.index(l[k - 1])
	print(f(a) // (f(b) * f(a - b)) % (10 ** 9 + 7))


from collections import defaultdict
from math import gcd
mod = 10 ** 9 + 7

def ncr(n, r):
	p = 1
	k = 1
	if n - r < r:
		r = n - r
	if r != 0:
		while r:
			p *= n % mod
			k *= r % mod
			m = gcd(p, k)
			p //= m
			k //= m
			n -= 1
			r -= 1
	else:
		p = 1
	return p
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	dic = defaultdict(int)
	for i in arr:
		dic[i] += 1
	tot = 0
	e = arr[k - 1]
	cnt = 0
	for i in range(k):
		tot += arr[i]
		if arr[i] == e:
			cnt += 1
	x = dic[e]
	ans = ncr(x, cnt)
	print(ans % mod)


in_length = int(input())
final_ouput = []
for i in range(in_length):
	[num_bloggers, av_contracts] = [int(el) for el in input().split()]
	followers_p_b = [int(el) for el in input().split()]
	followers_p_b = sorted(followers_p_b)
	followers_p_b.reverse()
	selected_bloggers = followers_p_b[:av_contracts]
	lowest = selected_bloggers[-1]
	n = followers_p_b.count(lowest)
	r = selected_bloggers.count(lowest)
	nr = n - r
	m = 10 ** 9 + 7
	for j in range(1, n):
		n = n * j
	for k in range(1, r):
		r = r * k
	for l in range(1, nr):
		nr = nr * l
	if n == 0:
		n = 1
	if r == 0:
		r = 1
	if nr == 0:
		nr = 1
	ans = n // r // nr % m
	final_ouput.append(ans)
for out in final_ouput:
	print(out)


def dell(lst, m):
	dic = {}
	for i in lst:
		try:
			dic[i] += 1
		except:
			dic[i] = 1
	bok = list(dic.keys())
	bok.sort(reverse=True)
	sum = num = 0
	for i in bok:
		num = dic[i]
		if sum + num >= m:
			break
		else:
			sum += num
	need = m - sum
	b = a = 1
	for i in range(num, num - need, -1):
		b *= i
	for i in range(1, need + 1):
		a *= i
	print(b // a % (10 ** 9 + 7))
t = int(input())
for u in range(t):
	l = input().split()
	lst = list(map(int, input().split()))
	dell(lst, int(l[1]))


import math
from collections import Counter as c
for _ in ' ' * int(input()):
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()))
	(t, b, s) = (c(a), c(a[-k:]), 1)
	for i in b:
		s *= math.comb(t[i], b[i]) % 1000000007
	print(s)


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
import math
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
t = 1
t = int(input())
for _ in range(t):
	(n, m) = li()
	a = li()
	dic = defaultdict(lambda : 0)
	for i in range(n):
		dic[a[i]] += 1
	a = list(set(a))
	a.sort(reverse=True)
	cnt = 1
	x = len(a)
	for i in range(x):
		if dic[a[i]] < m:
			m -= dic[a[i]]
			continue
		else:
			mod = 1000000007
			z = dic[a[i]]
			print(ncr(z, m, mod))
			break


mod = 10 ** 9 + 7

def choose(n, r):
	x = 1
	for i in range(n - r + 1, n + 1):
		x *= i
	for i in range(1, r + 1):
		x //= i
	return x % mod
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = sum(arr[0:k])
	freq = [0] * (n + 1)
	for i in range(n):
		freq[arr[i]] += 1
	i = n
	while k >= freq[i]:
		k -= freq[i]
		i -= 1
	print(choose(freq[i], k))


import sys
input = sys.stdin.buffer.readline
mod = 10 ** 9 + 7

def cmb(n, r):
	if r < 0 or r > n:
		return 0
	return g1[n] * g2[r] * g2[n - r] % mod
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, 10003):
	g1.append(g1[-1] * i % mod)
	inv.append(-inv[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inv[-1] % mod)
for t in range(int(input())):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort(reverse=True)
	C = [0] * (N + 1)
	for i in range(N):
		C[A[i]] += 1
	B = A[:K]
	X = B[-1]
	Y = B.count(X)
	print(cmb(C[X], Y))


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from math import sqrt, pi, ceil, log, inf, gcd, floor
from itertools import combinations, permutations
from bisect import *
from fractions import Fraction
from heapq import *
from random import randint

def main():
	mod = 10 ** 9 + 7
	n = 1000
	fac = [1]
	for i in range(1, n + 1):
		fac.append(fac[-1] * i % mod)
	invfac = [0] * (n + 1)
	invfac[-1] = pow(fac[-1], mod - 2, mod)
	for i in range(n - 1, -1, -1):
		invfac[i] = invfac[i + 1] * (i + 1) % mod
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		a = sorted(map(int, input().split()), reverse=True)
		z = sum(a[:k])
		m = a.count(a[k - 1])
		r = a[:k].count(a[k - 1])
		print(fac[m] * invfac[m - r] * invfac[r] % mod)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import collections
import string
import math
import copy
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
mo = int(1000000000.0 + 7)

def exgcd(a, b):
	if not b:
		return (1, 0)
	(y, x) = exgcd(b, a % b)
	y -= a // b * x
	return (x, y)

def getinv(a, m):
	(x, y) = exgcd(a, m)
	return --1 if x == 1 else x % m

def comb(n, b):
	res = 1
	b = min(b, n - b)
	for i in range(b):
		res = res * (n - i) * getinv(i + 1, mo) % mo
	return res % mo

def quickpower(a, n):
	res = 1
	while n:
		if n & 1:
			res = res * a % mo
		n >>= 1
		a = a * a % mo
	return res

def dis(a, b):
	return abs(a[0] - b[0]) + abs(a[1] - b[1])

def getpref(x):
	if x > 1:
		return x * (x - 1) >> 1
	else:
		return 0
t = int(input())
for ti in range(t):
	(n, m) = map(int, input().split())
	l1 = [int(i) for i in input().split()]
	l1.sort()
	mi = 0
	ctr1 = 1
	ctr2 = 0
	idx = n - m
	cur = l1[idx]
	idx2 = idx + 1
	while idx2 < len(l1) and l1[idx2] == cur:
		idx2 += 1
		ctr1 += 1
	idx3 = idx - 1
	while idx3 >= 0 and l1[idx3] == cur:
		ctr2 += 1
		idx3 -= 1
	print(comb(ctr1 + ctr2, ctr1))


from collections import defaultdict, deque
from sys import stdin
from math import comb
input = lambda : stdin.readline().strip()
for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	lst = [int(i) for i in input().split()]
	lst.sort(reverse=True)
	nd = 0
	lst2 = deque()
	while nd < k:
		lst2.append(lst[nd])
		nd += 1
	a = lst2[-1]
	nk = 0
	nm = 0
	while nd < n:
		if lst[nd] == a:
			nk += 1
		else:
			break
		nd += 1
	lst2 = list(lst2)[::-1]
	for i in lst2:
		if i == a:
			nm += 1
		else:
			break
	print(comb(nm + nk, nm) % 1000000007)


import sys
input = sys.stdin.readline
t = int(input())
mod = 10 ** 9 + 7
for tests in range(t):
	(n, k) = map(int, input().split())
	A = sorted(map(int, input().split()), reverse=True)
	x = A[k - 1]
	count = 0
	for a in A:
		if a > x:
			k -= 1
		if a == x:
			count += 1
	ANS = 1
	for i in range(k):
		ANS = ANS * (count - i) * pow(i + 1, mod - 2, mod) % mod
	print(ANS)


from collections import defaultdict
import math

def foo(n, r):
	return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
t = int(input())
mod = pow(10, 9) + 7
for t1 in range(0, t):
	d = defaultdict(int)
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	for i in l:
		d[i] += 1
	l.sort()
	temp = []
	last = n - 1
	count = 0
	while count < k:
		temp.append(l[last])
		last -= 1
		count += 1
	cd = defaultdict(int)
	for i in temp:
		cd[i] += 1
	ans = 1
	stemp = list(set(temp))
	for i in stemp:
		ans = ans * (foo(d[i], cd[i]) % mod) % mod
	print(ans)


from collections import defaultdict
import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	mod = 10 ** 9 + 7
	a.sort()
	last = a[-k]
	c = a.count(last)
	start = n - k
	cnt = 0
	while start < n and a[start] == last:
		start += 1
		cnt += 1
	ans = math.factorial(c)
	ans //= math.factorial(cnt)
	ans //= math.factorial(c - cnt)
	ans = ans % mod
	print(ans)


import math
T = int(input())
for testcase in range(1, T + 1):
	(n, k) = [int(s) for s in input().split(' ')]
	a = [0 for x in range(n)]
	l = input().split()
	for (y, name) in enumerate(l):
		a[y] = int(l[y])
	a.sort(reverse=True)
	lastVal = a[0]
	count = 1
	myList = []
	for i in range(1, n):
		if a[i] == lastVal:
			count += 1
		else:
			myList.append([lastVal, count])
			lastVal = a[i]
			count = 1
	myList.append([lastVal, count])
	i = 0
	while k > 0:
		k -= myList[i][1]
		i += 1
	if k == 0:
		print(1)
	else:
		x = myList[i - 1][1]
		y = -k
		z = math.factorial(x) // math.factorial(y) // math.factorial(x - y) % (10 ** 9 + 7)
		print(z)


def modPower(x, y):
	M = 10 ** 9 + 7
	res = 1
	while y:
		if y % 2 == 1:
			res = res * x % M
		x = x * x % M
		y = y // 2
	return res
M = 10 ** 9 + 7
fact = [0] * 1001
rfact = [0] * 1001
fact[0] = 1
rfact[0] = 1
for i in range(1, 1001):
	fact[i] = fact[i - 1] * i % M
	rfact[i] = modPower(fact[i], M - 2)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ll = list(map(int, input().split()))
	ll.sort()
	req = ll[n - k]
	a = 0
	for i in range(n):
		if ll[i] == req:
			a += 1
	b = 0
	for i in range(n - k, n):
		if ll[i] == req:
			b += 1
	ans = fact[a] % M * rfact[b] % M % M
	print(ans * rfact[a - b] % M)


from collections import defaultdict
from math import comb
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dic = defaultdict(lambda : 0)
	a.sort()
	arr = a[-k:]
	temp = arr.count(arr[0])
	ans = comb(a.count(arr[0]), temp)
	print(ans % (10 ** 9 + 7))


import sys
from math import factorial
from collections import Counter
inline = sys.stdin.readline

def comb(n, k):
	return factorial(n) // factorial(k) // factorial(n - k)

def solution(arr, k):
	arr.sort(reverse=True)
	num = arr[k - 1]
	n = Counter(arr)[num]
	k = Counter(arr[:k])[num]
	return comb(n, k) % (10 ** 9 + 7)
T = int(inline().strip())
for t in range(T):
	(_, k) = map(int, inline().strip().split())
	arr = list(map(int, inline().strip().split()))
	print(solution(arr, k))


from collections import Counter
import operator as op
from functools import reduce

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	d = l[n - k:]
	s = sum(l)
	c = Counter(l)
	dd = Counter(d)
	ans = 1
	for i in dd:
		ans *= ncr(c[i], dd[i])
	print(ans % (10 ** 9 + 7))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	t = a.count(a[k - 1])
	s = 0
	j = k - 1
	while a[j] == a[k - 1] and j >= 0:
		s += 1
		j -= 1
	if len(set(a)) == 1:
		s = k
		t = n
	ans = math.factorial(t) // (math.factorial(t - s) * math.factorial(s))
	print(ans % 1000000007)


import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def SieveOfEratosthenes(n):
	prime = []
	primes = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if primes[p] == True:
			prime.append(p)
			for i in range(p * p, n + 1, p):
				primes[i] = False
		p += 1
	return prime

def primefactors(n):
	fac = []
	while n % 2 == 0:
		fac.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 2):
		while n % i == 0:
			fac.append(i)
			n = n // i
	if n > 1:
		fac.append(n)
	return fac

def factors(n):
	fac = set()
	fac.add(1)
	fac.add(n)
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			fac.add(i)
			fac.add(n // i)
	return list(fac)

def NcR(n, r):
	p = 1
	k = 1
	if n - r < r:
		r = n - r
	if r != 0:
		while r:
			p *= n
			k *= r
			m = math.gcd(p, k)
			p //= m
			k //= m
			n -= 1
			r -= 1
	else:
		p = 1
	return p
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	dic = {}
	a = a[::-1]
	for i in range(0, len(a)):
		if a[i] in dic:
			dic[a[i]] += 1
		else:
			dic[a[i]] = 1
	dic2 = {}
	for i in range(k):
		if a[i] in dic2:
			dic2[a[i]] += 1
		else:
			dic2[a[i]] = 1
	ans = 1
	for i in dic:
		if i in dic2:
			taken = dic2[i]
			numbers = dic[i]
			ans = ans * NcR(numbers, taken) % (10 ** 9 + 7)
	print(ans)


from math import comb

def choose():
	for i in range(int(input())):
		(n, k) = list(map(int, input().split()))
		li = sorted(list(map(int, input().split())), reverse=True)
		y = li.count(li[k - 1])
		x = li[:k].count(li[k - 1])
		print(comb(y, x) % (10 ** 9 + 7))
choose()


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, gcd
import bisect
import sys
import copy

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
N = 1001
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)

def InverseofNumber(p):
	naturalNumInverse[0] = naturalNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		naturalNumInverse[i] = naturalNumInverse[p % i] * (p - int(p / i)) % p

def InverseofFactorial(p):
	factorialNumInverse[0] = factorialNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		factorialNumInverse[i] = naturalNumInverse[i] * factorialNumInverse[i - 1] % p

def factorial(p):
	fact[0] = 1
	for i in range(1, N + 1):
		fact[i] = fact[i - 1] * i % p

def Binomial(N, R, p):
	ans = fact[N] * factorialNumInverse[R] % p * factorialNumInverse[N - R] % p
	return ans
p = 1000000007
InverseofNumber(p)
InverseofFactorial(p)
factorial(p)
for _ in range(int(input())):
	(n, k) = get_ints()
	a = get_array()
	d = defaultdict(int)
	for i in a:
		d[i] += 1
	a.sort(reverse=True)
	ans = a[:k]
	cnt = 0
	ind = k - 1
	while ind >= 0 and ans[ind] == ans[k - 1]:
		ind -= 1
		cnt += 1
	act_ans = Binomial(d[ans[-1]], cnt, p)
	print(act_ans)


from collections import defaultdict
N = 1001
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)

def InverseofNumber(p):
	naturalNumInverse[0] = naturalNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		naturalNumInverse[i] = naturalNumInverse[p % i] * (p - int(p / i)) % p

def InverseofFactorial(p):
	factorialNumInverse[0] = factorialNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		factorialNumInverse[i] = naturalNumInverse[i] * factorialNumInverse[i - 1] % p

def factorial(p):
	fact[0] = 1
	for i in range(1, N + 1):
		fact[i] = fact[i - 1] * i % p

def Binomial(N, R, p):
	ans = fact[N] * factorialNumInverse[R] % p * factorialNumInverse[N - R] % p
	return ans
p = 10 ** 9 + 7
InverseofNumber(p)
InverseofFactorial(p)
factorial(p)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	a.reverse()
	cnt = [0] * (n + 1)
	for j in range(n):
		cnt[a[j]] += 1
	d1 = defaultdict(lambda : 0)
	j = 0
	while j < k:
		d1[a[j]] += 1
		j += 1
	print(Binomial(cnt[a[k - 1]], d1[a[k - 1]], p) % p)


from math import factorial
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	g = sorted(a, reverse=True)[:k]
	n1 = a.count(g[-1])
	r1 = g.count(g[-1])
	print(factorial(n1) // (factorial(n1 - r1) * factorial(r1)) % (10 ** 9 + 7))


import math
from itertools import combinations
for i in range(int(input())):
	(n, k) = map(int, input().split())
	ls = list(map(int, input().split()))
	ls.sort(reverse=True)
	sum = 0
	if ls[k - 1] not in ls[k:]:
		print(1)
	else:
		s = ls.count(ls[k - 1])
		m = ls[0:k].count(ls[k - 1])
		print(math.comb(s, m) % (10 ** 9 + 7))


from math import comb
t = int(input())
for i in range(t):
	(n, k) = [int(i) for i in input().split()]
	ch = dict()
	l = list()
	for i in input().split():
		if int(i) not in ch:
			l.append(int(i))
			ch[int(i)] = 1
		else:
			ch[int(i)] += 1
	l.sort(reverse=True)
	cur = 0
	ind = 0
	prev = None
	flag = False
	while ind < len(l):
		prev = cur
		cur += ch[l[ind]]
		if cur == k:
			flag = True
			print(1)
			break
		elif cur > k:
			break
		ind += 1
	if flag:
		continue
	print(comb(ch[l[ind]], cur - k) % (10 ** 9 + 7))


mod = 1000000000.0 + 7
c = [[0 for i in range(1005)] for j in range(1005)]
c[0][0]
for i in range(1, 1001):
	c[i][0] = c[i][i] = 1
	for j in range(1, i):
		c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	d = list(map(int, input().split()))
	d.sort(reverse=True)
	d.insert(0, 0)
	p = 0
	q = 0
	for j in range(1, n + 1):
		if d[j] == d[k]:
			p += 1
	for j in range(1, k + 1):
		if d[j] == d[k]:
			q += 1
	print('%d' % c[p][q])


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
f = [1] * 1001
fi = [1] * 1001
a = 1
m = 10 ** 9 + 7
for i in range(1, 1001):
	a *= i
	a %= m
	f[i] = a
b = pow(f[1000], m - 2, m)
fi[1000] = b
for i in range(999, 0, -1):
	fi[i] = b * (i + 1) % m
	b = fi[i]
for t in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	l1 = [0] * (n + 1)
	for i in l:
		l1[i] += 1
	a = l.index(l[k - 1])
	a = k - a
	print(f[l1[l[k - 1]]] * fi[l1[l[k - 1]] - a] * fi[a] % m)


from sys import stdin
import sys

def modfac(n, MOD):
	f = 1
	factorials = [1]
	for m in range(1, n + 1):
		f *= m
		f %= MOD
		factorials.append(f)
	inv = pow(f, MOD - 2, MOD)
	invs = [1] * (n + 1)
	invs[n] = inv
	for m in range(n, 1, -1):
		inv *= m
		inv %= MOD
		invs[m - 1] = inv
	return (factorials, invs)

def modnCr(n, r, mod, fac, inv):
	return fac[n] * inv[n - r] * inv[r] % mod
mod = 10 ** 9 + 7
(fac, inv) = modfac(2000, mod)
tt = int(stdin.readline())
for loop in range(tt):
	(n, k) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	a.sort()
	a.reverse()
	x = a[k - 1]
	cnt = 0
	xnum = 0
	for i in range(n):
		if a[i] == x:
			cnt += 1
			if i < k:
				xnum += 1
	print(modnCr(cnt, xnum, mod, fac, inv) % mod)


import math
import sys
from collections import *
from time import sleep
input = sys.stdin.readline
MOD = int(10 ** 9 + 7)

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
ret = []
for i in range(t):
	(n, k) = inlt()
	l = inlt()
	ls = Counter(l)
	keys = sorted(ls.keys(), reverse=True)
	for key in keys:
		k -= ls[key]
		if k <= 0:
			ret.append(math.comb(ls[key], k + ls[key]) % MOD)
			break
for r in ret:
	print(r)


import math
I = lambda : [*map(int, input().split())]
(t,) = I()
for _ in ' ' * t:
	(n, k) = I()
	l = sorted(I())
	a = l[-k]
	print(math.comb(l.count(a), l[-k:].count(a)) % (10 ** 9 + 7))


from math import comb
m = 10 ** 9 + 7
for t in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	l1 = [0] * (n + 1)
	for i in l:
		l1[i] += 1
	a = l.index(l[k - 1])
	a = k - a
	print(comb(l1[l[k - 1]], a) % m)


fac = [0 for i in range(1001)]
fac[0] = 1
mod = 10 ** 9 + 7
for i in range(1, 1001):
	fac[i] = fac[i - 1] * i % mod
for tt in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	mi = 1001
	cnt = 0
	for i in range(k):
		if l[i] == mi:
			cnt += 1
		else:
			cnt = 1
		mi = min(mi, l[i])
	cnt1 = cnt
	for i in range(k, n):
		if l[i] == mi:
			cnt1 += 1
		else:
			break
	print(fac[cnt1] * pow(fac[cnt], mod - 2, mod) % mod * pow(fac[cnt1 - cnt], mod - 2, mod) % mod)


import sys
input = sys.stdin.readline
from collections import *
MAX = 1010
MOD = 10 ** 9 + 7
fact = [0] * MAX
inv = [0] * MAX
finv = [0] * MAX
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
	fact[i] = fact[i - 1] * i % MOD
	inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
	finv[i] = finv[i - 1] * inv[i] % MOD

def C(n, r):
	if n < r:
		return 0
	if n < 0 or r < 0:
		return 0
	return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	cnt = Counter(a)
	a.sort(reverse=True)
	top = a[:k]
	m = top[-1]
	c1 = cnt[m]
	c2 = top.count(m)
	print(C(c1, c2))


from math import comb

def swapp(n, k, a):
	a.sort(reverse=True)
	kk = 0
	su = 0
	p = 0
	dd = 0
	if n == k:
		return 1
	for i in range(k - 1, n - 1):
		if a[i] != a[i + 1]:
			break
		if a[i] == a[i + 1]:
			p = a[i]
	if p == 0:
		return 1
	if p > 0:
		for i in range(k - 1):
			if a[k - i - 1] == a[k - i - 2]:
				dd += 1
			else:
				break
		ss = a.count(p)
		return comb(ss, min(1 + dd, k)) % 1000000007
t = int(input())
for i in range(t):
	NM = input().split()
	n = int(NM[0])
	k = int(NM[1])
	a = list(map(int, input().rstrip().split()))
	ans = swapp(n, k, a)
	print(ans)


MOD = 10 ** 9 + 7
import math
import functools

def euler_criterion(a, p):
	return pow(a, (p - 1) // 2, p) == 1

def gcd(a, b):
	a = abs(a)
	b = abs(b)
	while a > 0:
		b = b % a
		tmp = a
		a = b
		b = tmp
	return b

def xgcd(a, b):
	a1 = 1
	b1 = 0
	a2 = 0
	b2 = 1
	aneg = 1
	bneg = 1
	if a < 0:
		a = -a
		aneg = -1
	if b < 0:
		b = -b
		bneg = -1
	while 1:
		quot = -(a // b)
		a = a % b
		a1 = a1 + quot * a2
		b1 = b1 + quot * b2
		if a == 0:
			return (b, a2 * aneg, b2 * bneg)
		quot = -(b // a)
		b = b % a
		a2 = a2 + quot * a1
		b2 = b2 + quot * b1
		if b == 0:
			return (a, a1 * aneg, b1 * bneg)

def power_mod(b, e, n):
	if e < 0:
		e = -e
		b = inverse_mod(b, n)
	accum = 1
	i = 0
	bpow2 = b
	while e >> i > 0:
		if e >> i & 1:
			accum = accum * bpow2 % n
		bpow2 = bpow2 * bpow2 % n
		i += 1
	return accum

def inverse_mod(a, n):
	(g, xa, xb) = xgcd(a, n)
	if g != 1:
		raise ValueError('***** Error *****: {0} has no inverse (mod {1}) as their gcd is {2}, not 1.'.format(a, n, g))
	return xa % n

def C(n, r):
	if r > n // 2:
		return C(n, n - r)
	x = 1
	for i in range(r):
		x *= n - i
		x %= MOD
	d = 1
	for i in range(r):
		d *= i + 1
		d %= MOD
	d = inverse_mod(d, MOD)
	return d * x % MOD

def main():
	t = int(input())
	while t > 0:
		t -= 1
		(n, k) = map(int, input().split())
		data = list(map(int, input().split()))
		data.sort(reverse=True)
		if len(data) <= k:
			print(1)
		else:
			last = data[k]
			count = 0
			for i in data:
				if i == last:
					count += 1
			my_cnt = 0
			for i in range(k):
				if data[i] == last:
					my_cnt += 1
			print(C(count, my_cnt))
main()


from math import comb
for i in range(int(input())):
	(a, k) = map(int, input().split())
	arr = [int(arr) for arr in input().split()]
	arr.sort()
	goal = arr[-k:]
	s = 1
	for i in range(len(goal)):
		if i > 0 and goal[i] == goal[i - 1]:
			continue
		s = s * comb(arr.count(goal[i]), goal.count(goal[i]))
	print(s % (10 ** 9 + 7))


import math
from collections import Counter

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = Counter(l)
	l.sort(reverse=1)
	ans = 1
	a = l[k - 1]
	i = k - 1
	c = 0
	while i > -1:
		if l[i] == a:
			c += 1
		else:
			break
		i -= 1
	x = nCr(d[a], c)
	print(x % (10 ** 9 + 7))


from sys import stdin, stdout, maxsize
from math import sqrt, log, factorial, gcd
from collections import defaultdict as D, OrderedDict as OD
from bisect import insort
for _ in range(int(input())):
	(n, k) = map(int, input().strip().split())
	a = sorted(list(map(int, stdin.readline().strip().split())), reverse=True)
	d = D(lambda : 0)
	for i in range(k):
		d[a[i]] += 1
	d1 = D(lambda : 0)
	for i in a:
		d1[i] += 1
	ways = 1
	for i in d:
		ways *= factorial(d1[i]) // (factorial(d[i]) * factorial(d1[i] - d[i]))
	print(ways % 1000000007)


from math import comb
mod = int(pow(10, 9)) + 7
for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	arr = sorted(arr, reverse=True)
	(l, r) = (k - 1, k - 1)
	while r < n and arr[r] == arr[k - 1]:
		r += 1
	while l >= 0 and arr[l] == arr[k - 1]:
		l -= 1
	r -= 1
	l += 1
	print(comb(r - l + 1, k - l) % mod)


from sys import stdin
nii = lambda : map(int, stdin.readline().split())
lnii = lambda : list(map(int, stdin.readline().split()))
t = int(input())
mod = 10 ** 9 + 7
MAX_N = 10 ** 3 + 5
fac = [1, 1] + [0] * MAX_N
finv = [1, 1] + [0] * MAX_N
inv = [0, 1] + [0] * MAX_N
for i in range(2, MAX_N):
	fac[i] = fac[i - 1] * i % mod
	inv[i] = mod - inv[mod % i] * (mod // i) % mod
	finv[i] = finv[i - 1] * inv[i] % mod

def nCk(n, k):
	if n < k:
		return 0
	if n < 0 or k < 0:
		return 0
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod
for tt in range(t):
	(n, k) = nii()
	a = lnii()
	a.sort(reverse=True)
	target = a[k - 1]
	num = a[:k].count(target)
	count = a.count(target)
	ans = nCk(count, num) % mod
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def nCr(n, r):
	return fact(n) // (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	x = {}
	for i in a:
		x[i] = x.get(i, 0) + 1
	y = {}
	a.sort(reverse=True)
	for i in range(k):
		y[a[i]] = y.get(a[i], 0) + 1
	ans = 1
	for i in y.keys():
		ans *= nCr(x[i], y[i])
	print(ans % (10 ** 9 + 7))


import math
for _ in range(int(input())):
	(n, k) = [*map(int, input().split())]
	l = [*map(int, input().split())]
	l.sort(reverse=True)
	x = l.count(l[k - 1])
	y = 0
	for i in range(k, n):
		if l[i] != l[k - 1]:
			break
		y += 1
	MOD = 10 ** 9 + 7
	print(math.comb(x, y) % MOD)


import math

def c(k, n):
	return math.factorial(n) // (math.factorial(k) * math.factorial(n - k)) % (10 ** 9 + 7)

def solve():
	(n, k) = map(int, input().split())
	a = []
	for i in input().split():
		a.append(int(i))
	a.sort()
	m = dict()
	for i in a:
		if m.get(i, 0) == 0:
			m[i] = 1
		else:
			m[i] += 1
	ind = n - k
	while ind < n - 1 and a[ind + 1] == a[ind]:
		ind += 1
	print(c(ind - (n - k) + 1, m[a[n - k]]))
t = int(input())
while t > 0:
	t -= 1
	solve()


def aCb(a, b):
	prod = 1
	for f in range(a - b + 1, a + 1):
		prod = prod * f
	pro = 1
	for j in range(1, b + 1):
		pro = pro * j
	return prod // pro
t = int(input())
for z in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	mf = []
	for i in range(k):
		mf.append(arr[i])
	q = list(set(mf))
	cou = 1
	for num in q:
		a = arr.count(num)
		b = mf.count(num)
		cou = cou * aCb(a, b)
		cou = cou % 1000000007
	print(cou)


import os, sys
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
fac = [1]
for i in range(1, 10 ** 5 + 1):
	fac.append(fac[-1] * i % mod)
fac_in = [pow(fac[-1], mod - 2, mod)]
for i in range(10 ** 5, 0, -1):
	fac_in.append(fac_in[-1] * i % mod)
fac_in.reverse()

def comb(a, b):
	if a < b:
		return 0
	return fac[a] * fac_in[a - b] * fac_in[b] % mod

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		a = sorted(list(map(int, input().split())), reverse=1)
		ls = [0] * (n + 1)
		for i in a:
			ls[i] += 1
		z = ls[a[k - 1]]
		x = 0
		for i in a:
			if i == a[k - 1]:
				break
			x += 1
		print(comb(z, k - x))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def getn(a, b):
	ans = 1
	div = 1
	for i in range(0, b):
		ans *= a - i
	for i in range(1, b + 1):
		div *= i
	ans //= div
	return ans % 1000000007
tot = int(input())
for i in range(0, tot):
	mp = list(input().split())
	n = int(mp[0])
	k = int(mp[1])
	mp = list(input().split())
	lst = list()
	dct = dict()
	for i in mp:
		t = int(i)
		if dct.get(t, 0) > 0:
			dct[t] += 1
		else:
			dct[t] = 1
			lst.append(t)
	lst.sort()
	i = 0
	ans = 1
	while i < k:
		t = lst.pop()
		dt = dct[t]
		gets = min(dt, k - i)
		ans *= getn(dt, gets)
		ans %= 1000000007
		i += gets
	print(ans)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	a = l[-k:]
	count = 1
	for i in set(a):
		a1 = a.count(i)
		a2 = l.count(i)
		a3 = math.factorial(a2) // math.factorial(a1) // math.factorial(a2 - a1)
		count *= a3
	print(count % 1000000007)


mod = int(1000000000.0 + 7)

def fact(n):
	ans = 1
	for i in range(2, n + 1):
		ans = ans * i
	return ans

def comb(n, k):
	ans = fact(n)
	ans //= fact(k) * fact(n - k)
	return ans % mod
for insjdfsdf in range(int(input())):
	(n, k) = map(int, input().split())
	L = list(map(int, input().split()))
	us = [0 for i in range(n + 1)]
	for i in range(n):
		us[L[i]] += 1
	L.sort(reverse=True)
	ans = 1
	least = L[k - 1]
	for i in range(k):
		x = L[i]
		if x == least:
			T = comb(us[x], k - i)
			ans = ans * T
			break
	print(ans)


mod = 10 ** 9 + 7
from math import comb
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()), reverse=True)
	count = 1
	before = a[0]
	i = 0
	for i in range(1, k):
		if not before == a[i]:
			count = 1
			before = a[i]
		else:
			count += 1
	countb = count
	i += 1
	if i < n:
		while a[i] == before:
			i += 1
			countb += 1
			if i >= n:
				break
	print(comb(countb, count) % mod)


from math import comb, prod

def advert(arr, k):
	arr = sorted(arr, reverse=True)
	temp = arr[:k]
	ans = 1
	pp = []
	for i in set(arr[:k]):
		pp.append(comb(arr.count(i), temp.count(i)))
	return prod(pp) % (10 ** 9 + 7)
for i in range(int(input())):
	(a, b) = map(int, input().strip().split())
	lst = list(map(int, input().strip().split()))
	print(advert(lst, b))


from math import *
from collections import *
for u in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	d = defaultdict(int)
	for i in l:
		d[i] += 1
	c = 1
	s = 1
	for i in range(k):
		if i > 0:
			if l[i - 1] == l[i]:
				c += 1
			else:
				c = 1
		s = s * d[l[i]] // c
		d[l[i]] -= 1
	print(s % (10 ** 9 + 7))


fact = [1]
x = 1
for i in range(1, 1001):
	x = x * i
	fact.append(x)
from sys import stdin
input = stdin.buffer.readline
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	arr.sort()
	p = n - k
	cc = arr.count(arr[p])
	cnt = 0
	i = p
	while i < n and arr[i] == arr[p]:
		cnt = cnt + 1
		i = i + 1
	print(fact[cc] // (fact[cnt] * fact[cc - cnt]) % 1000000007)


from math import comb
from collections import Counter
for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	if n == k:
		print(1)
		continue
	a.sort(reverse=True)
	cnt = Counter(a)
	c = 0
	for i in cnt:
		if c + cnt[i] > k:
			print(comb(cnt[i], k - c) % 1000000007)
			break
		else:
			c += cnt[i]


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from itertools import permutations as per
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
f = [1]
for i in range(1, 1001):
	f += (f[i - 1] * i % N,)
for _ in range(I()):
	(n, k) = R()
	a = sorted(R(), reverse=True)
	fr = 0
	b = 0
	for i in range(k, n):
		if a[i] == a[k - 1]:
			b += 1
		else:
			break
	for i in range(k - 1, -1, -1):
		if a[i] == a[k - 1]:
			fr += 1
		else:
			break
	print(nCr(b + fr, fr))


def binomial(n, k):
	if not 0 <= k <= n:
		return 0
	b = 1
	for t in range(min(k, n - k)):
		b *= n
		b //= t + 1
		n -= 1
	return b
for t in range(0, int(input())):
	(n, k) = tuple(map(int, input().split()))
	a = list(map(int, input().split()))
	if k == 0:
		print(0)
	elif n == 1:
		print(1)
	else:
		a = sorted(a, reverse=True)
		i = 0
		count = 0
		nums = []
		while count < k:
			nums.append(a[i])
			i += 1
			count += 1
		mn = min(nums)
		x = nums.count(mn)
		y = a.count(mn)
		ans = binomial(y, x)
		print(ans % (10 ** 9 + 7))


fact = [1]
for i in range(1, 1002):
	fact.append(fact[i - 1] * i)

def comb(n, k):
	return fact[n] // (fact[n - k] * fact[k])
for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	store = {}
	for i in a:
		if i in store:
			store[i] += 1
		else:
			store[i] = 1
	a = sorted(list(set(a)))
	count = 0
	for i in a[::-1]:
		if count + store[i] >= k:
			ans = comb(store[i], k - count)
			break
		count += store[i]
	print(ans % (10 ** 9 + 7))


t = int(input())

def nCr(n, r):
	return fact(n) // (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res
for _ in range(t):
	(n, k) = map(int, input().split())
	p = list(map(int, input().split()))
	p = sorted(p, reverse=True)
	d = {}
	for i in p:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	x = p[:k]
	x.reverse()
	t = x[0]
	i = 0
	while i < len(x) and x[i] == t:
		i += 1
	print(int(nCr(d[t], i)) % 1000000007)


from math import factorial
M = 10 ** 9 + 7

def C(n, k):
	return factorial(n) // (factorial(k) * factorial(n - k))
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	ans = 1
	d = dict()
	for i in a:
		d[i] = d.get(i, 0) + 1
	arr = []
	for i in d:
		arr.append([i, d[i]])
	arr.sort(key=lambda x: x[0], reverse=True)
	for i in range(len(arr)):
		if arr[i][1] > k:
			ans = C(arr[i][1], k)
			break
		else:
			k -= arr[i][1]
	print(ans % M)


rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input()
yn = lambda x: print('Yes') if x else print('No')
YN = lambda x: print('YES') if x else print('NO')
pl = lambda l: print(' '.join(list(map(str, l))))

def d(a):
	d = {}
	for i in a:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	return d
from math import comb
for _ in range(rn()):
	(n, k) = rns()
	a = rl()
	a.sort()
	num = a[n - k]
	count = 1
	while n - k + count < n and a[n - k + count] == num:
		count += 1
	ans = comb(a.count(num), count)
	print(ans % (10 ** 9 + 7))


import math
Y = lambda : map(int, input().split())
for _ in range(next(Y())):
	(n, k) = Y()
	a = sorted(Y())
	v = a[-k]
	print(math.comb(a.count(v), a[-k:].count(v)) % (10 ** 9 + 7))


import sys
mod = int(1000000000.0 + 7)
inv = [0] * int(10000.0)

def precalc(upper_bound, m=mod):
	upper_bound = int(upper_bound)
	inv[1] = 1
	for i in range(2, upper_bound):
		inv[i] = m - m // i * inv[m % i] % m

def choose(n, r, m=mod):
	n = int(n)
	r = int(r)
	m = int(m)
	if r == 1:
		return n % m
	res = 1
	for i in range(0, r):
		res *= (n - i) % m * inv[i + 1] % m
	return res % m
T = int(input())
precalc(1000.0 + 10)
while T:
	m = list(map(int, input().split(' ')))
	(n, k) = (int(m[0]), int(m[1]))
	a = list()
	a = list(map(int, input().split(' ')))
	freq = [0] * 1010
	for i in range(n):
		freq[a[i]] += 1
	a.sort(reverse=True)
	ans = 1
	last = a[k - 1]
	ch = k
	for i in range(k):
		ch -= 1
		if a[i] == last:
			ans = choose(freq[a[i]], ch + 1)
			break
	print(int(ans))
	T -= 1


from math import comb
MOD = int(1000000000.0 + 7)
t = int(input())
while t:
	line = input().split(' ')
	n = int(line[0])
	k = int(line[1])
	numbers = [int(x) for x in input().split(' ')]
	numbers = tuple(sorted(numbers))
	strt = n - k
	el = numbers[strt]
	cnt = 1
	for x in numbers[strt + 1:]:
		if x != el:
			break
		cnt = cnt + 1
	tot = cnt
	for x in numbers[:strt]:
		if x == el:
			tot += 1
	print(comb(tot, cnt) % MOD)
	t = t - 1


import sys
input = sys.stdin.readline
M = 10 ** 9 + 7

def inv(n):
	return power(n, M - 2)

def power(x, y):
	ans = 1
	while y > 0:
		if y % 2 == 1:
			ans = ans * x % M
		y = y // 2
		x = x * x % M
	return ans % M

def com(n, r):
	if r == 0:
		return 1
	else:
		return f[n] * inv(f[n - r]) % M * inv(f[r]) % M % M
f = [1]
x = 1
for i in range(1, 10 ** 5 + 3):
	x = x * i % M
	f.append(x)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	i = n - 1
	cnt = 0
	p = {}
	while cnt != k:
		x = l[i]
		if x in p:
			p[x] += 1
		else:
			p[x] = 1
		cnt += 1
		i -= 1
	d = {}
	for i in l:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	ans = 1
	for i in p:
		r = p[i]
		n = d[i]
		ans = ans * com(n, r) % M
	print(ans)


import sys
MOD = 1000000007
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(sys.stdin.readline())

def get_line():
	return sys.stdin.readline().strip()

def write_line(out):
	return sys.stdout.write(str(out) + '\n')

def solve():
	(n, k) = get_ints()
	followers = list(get_ints())
	followers.sort(reverse=True)
	count = followers.count(followers[k - 1])
	i = k - 1
	r = 0
	while i >= 0 and followers[i] == followers[k - 1]:
		r += 1
		i -= 1
	return math.comb(count, r) % MOD
t = get_int()
while t:
	write_line(solve())
	t -= 1


import sys
from typing import List, Literal
MOD: Literal[1000000007] = 1000000007
results: List[str] = []
_factorial_cache: List[int] = [1]

def factorial(n: int) -> int:
	try:
		return _factorial_cache[n]
	except IndexError:
		_factorial_cache.append(n * factorial(n - 1))
		return _factorial_cache[n]

def C(k: int, n: int) -> int:
	result = factorial(n) // (factorial(k) * factorial(n - k))
	return result % MOD

def solve() -> int:
	(n, k) = [int(i) for i in input().split()]
	followers = [int(f) for f in input().split()]
	followers.sort(reverse=True)
	start = -1
	for i in range(n):
		if followers[i] == followers[k - 1]:
			end = i
			if start == -1:
				start = i
	total = end - start + 1
	pick = k - 1 - start + 1
	return C(pick, total)
sys.setrecursionlimit(10000)
for _ in range(int(input())):
	results.append(str(solve()))
print('\n'.join(results))


import sys
import math
from sys import stdin, stdout

def sieve(N):
	primeNumbers = [True] * (N + 1)
	primeNumbers[0] = False
	primeNumbers[1] = False
	i = 2
	while i * i <= N:
		j = i
		if primeNumbers[j]:
			while j * i <= N:
				primeNumbers[j * i] = False
				j += 1
		i += 1
	return primeNumbers

def getPrime(N):
	primes = sieve(N)
	result = []
	for i in range(len(primes)):
		if primes[i]:
			result.append(i)
	return result

def factor(N):
	factors = []
	i = 1
	while i * i <= N:
		if N % i == 0:
			factors.append(i)
			if i != N // i:
				factors.append(N // i)
		i += 1
	return sorted(factors)

def gcd(a, b):
	if a < b:
		return gcd(b, a)
	if b == 0:
		return a
	return gcd(b, a % b)

def extendedGcd(a, b):
	if a < b:
		return extendedGcd(b, a)
	if b == 0:
		return [a, 1, 0]
	res = extendedGcd(b, a % b)
	x = res[2]
	y = res[1] - math.floor(a / b) * res[2]
	res[1] = x
	res[2] = y
	return res

def iterativeModularFunc(a, b, c):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % c
		a = a * a % c
		b = b // 2
	return res

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(input())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def modInverse(n, p):
	return pow(n, p - 2, p)

def Ncr(n, r, mod):
	if n < r:
		return 0
	if r == 0:
		return 1
	fac = [1 for _ in range(n + 1)]
	for i in range(1, n + 1):
		fac[i] = fac[i - 1] * i % mod
	return fac[n] * modInverse(fac[r], mod) % mod * modInverse(fac[n - r], mod) % mod % mod

def Solution(arr, n, k):
	arr = sorted(arr, reverse=True)
	kthEl = arr[k - 1]
	count = 0
	pos = 0
	for i in range(n):
		if i < k and kthEl == arr[i]:
			pos += 1
		if kthEl == arr[i]:
			count += 1
	ans = Ncr(count, pos, pow(10, 9) + 7)
	print(ans)

def main():
	for _ in range(get_int()):
		(n, k) = get_ints_in_variables()
		arr = get_ints_in_list()
		Solution(arr, n, k)
main()


import math as m

def ncr(n, r):
	return m.factorial(n) // (m.factorial(r) * m.factorial(n - r))
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = {}
	for i in range(n):
		if a[i] not in b.keys():
			b[a[i]] = 0
		b[a[i]] += 1
	c = []
	for i in b:
		c.append([i, b[i]])
	c.sort(reverse=True)
	f = 0
	for i in range(len(c)):
		if k - c[i][1] < 0:
			f = 1
			print(ncr(c[i][1], k) % (10 ** 9 + 7))
			break
		else:
			k = k - c[i][1]
	if f == 0:
		print(1)


def cnk_mod(max_n, m):
	cnk = [[1]]
	for n in range(1, max_n + 1):
		tmp = [1]
		for k in range(1, n):
			tmp.append((cnk[n - 1][k - 1] + cnk[n - 1][k]) % m)
		tmp.append(1)
		cnk.append(tmp)
	return cnk
M = 10 ** 9 + 7
cnk = cnk_mod(1001, M)
tests = int(input())
for t in range(tests):
	(n, k) = [int(s) for s in input().split()]
	a = [int(s) for s in input().split()]
	a.sort()
	x = 0
	i = n - k - 1
	while i >= 0 and a[i] == a[n - k]:
		x += 1
		i -= 1
	y = 0
	i = n - k
	while i < n and a[i] == a[n - k]:
		y += 1
		i += 1
	print(cnk[x + y][x])


try:
	from math import comb
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		l = [int(x) for x in input().split()]
		l.sort(reverse=True)
		n = l.count(l[k - 1])
		r = l[:k].count(l[k - 1])
		print(comb(n, r) % 1000000007)
except EOFError:
	pass


def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	result = 1
	if n > k:
		d = {}
		s = set()
		for i in a:
			if i not in d:
				d[i] = 1
				s.add(i)
			else:
				d[i] += 1
		s = sorted(list(s))
		s.reverse()
		for i in s:
			if k <= 0:
				break
			if d[i] <= k:
				k -= d[i]
			else:
				n = d[i]
				if 2 * k > n:
					k = n - k
				result = ncr(n, k, 10 ** 9 + 7)
				break
	print(result)


import sys
from collections import Counter
input = sys.stdin.readline
mod_ = 10 ** 9 + 7
factos = [1]
for i in range(1, 1001):
	factos.append(i * factos[-1] % mod_)

def solution(n, k, arr, mod_, factos):
	arr.sort()
	c = Counter(arr)
	c_k = Counter(arr[-k:])
	small_val = arr[-k]
	num = c[small_val]
	denum = c_k[small_val]
	sol = factos[num]
	sol = sol * pow(factos[num - denum], mod_ - 2, mod_) % mod_
	sol = sol * pow(factos[denum], mod_ - 2, mod_) % mod_
	print(sol)
T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	solution(n, k, arr, mod_, factos)


from sys import stdin
input = lambda : stdin.readline().strip()
lin = lambda : list(map(int, input().split()))
iin = lambda : int(input())
main = lambda : map(int, input().split())
from math import ceil, sqrt, factorial, log
from collections import deque
from bisect import bisect_left

def gcd(a, b):
	(a, b) = (max(a, b), min(a, b))
	while a % b != 0:
		(a, b) = (b, a % b)
	return b
mod = 998244353

def solve(we):
	(n, k) = main()
	l = lin()
	l.sort(reverse=True)
	t = l.count(l[k - 1])
	x = 0
	for i in range(k):
		if l[i] == l[k - 1]:
			x += 1
	ans = factorial(t) // (factorial(x) * factorial(t - x))
	print(ans % (pow(10, 9) + 7))
qwe = 1
qwe = int(input())
for _ in range(qwe):
	solve(_ + 1)


from collections import Counter
mod = 1000000007
factorials = [1]
for i in range(1, 1000001):
	factorials.append(factorials[-1] * i % mod)
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort(reverse=True)
	CA = Counter(A)
	first_k = A[:k]
	Ck = Counter(first_k)
	ans = 1
	for x in Ck:
		(n, r) = (CA[x], Ck[x])
		(fn, fr, fnr) = (factorials[n], factorials[r], factorials[n - r])
		ncr = fn * pow(fr * fnr, mod - 2, mod) % mod
		ans = ans * ncr % mod
	print(ans)


from math import comb
t = int(input())
for i in range(t):
	(n, k) = tuple(map(int, input().split()))
	list1 = list(map(int, input().split()))
	list1.sort()
	d1 = {}
	for element in list1[::-1]:
		if element in d1:
			d1[element] += 1
		else:
			d1[element] = 1
	for key in d1:
		if d1[key] >= k:
			print(comb(d1[key], k) % 1000000007)
			break
		else:
			k -= d1[key]


import math, sys
from collections import defaultdict, deque
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(sys.stdin.readline())

def In():
	return map(int, sys.stdin.readline().split())

def Sn():
	return sys.stdin.readline().strip()

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def main():
	try:
		(n, k) = In()
		l = list(In())
		d = dict(l)
		z = list(d.keys())
		z.sort(reverse=True)
		ans = [0] * len(z)
		for i in range(len(z)):
			if k > d[z[i]]:
				ans[i] = d[z[i]]
				k -= d[z[i]]
			else:
				ans[i] = k
				break
		for i in range(len(z)):
			if ans[i]:
				ans[i] = ncr(d[z[i]], ans[i], P)
			else:
				ans[i] = 1
		an = 1
		for x in ans:
			an *= x
			an %= P
		print(an)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


from math import *
from sys import *
from bisect import *
from collections import *

def fact(x):
	a = 1
	for i in range(1, x + 1):
		a *= i
	return a

def solve(n, k):
	x = fact(n)
	y = fact(k)
	z = fact(n - k)
	return x // (y * z)
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	a.sort()
	a = a[::-1]
	d = {}
	b = []
	for i in range(n):
		if a[i] not in d:
			d[a[i]] = 0
			b.append(a[i])
		d[a[i]] += 1
	f = 0
	j = 0
	for i in range(len(b)):
		k -= d[b[i]]
		if k < 0:
			f = 1
			j = i
			k += d[b[i]]
			break
		if k == 0:
			break
	if f == 1:
		ans = solve(d[b[j]], k)
		print(ans % 1000000007)
	else:
		print(1)


def combination(n, m):
	(a, b) = (1, 1)
	for i in range(m + 1, n + 1):
		a *= i
		if b <= n - m and a % b == 0:
			a //= b
			b += 1
	return a % (1000000000 + 7)

def agency():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	mp = {i: 0 for i in a}
	b = a[n - m]
	for i in a:
		mp[i] += 1
	k = 0
	for i in range(n - m, n):
		if a[i] != b:
			break
		k += 1
	return combination(mp[b], k)
for i in range(int(input())):
	print(agency())


import math
t = int(input())
for q in range(t):
	arrc = [0] * 1001
	end = 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	x = max(a)
	for i in a:
		arrc[i] += 1
	for i in range(x, 0, -1):
		if k >= arrc[i]:
			k -= arrc[i]
		else:
			end = math.factorial(arrc[i]) // (math.factorial(k) * math.factorial(arrc[i] - k))
			break
	print(end % (10 ** 9 + 7))


from collections import defaultdict as dd, deque as dq, Counter as ctr
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
from bisect import bisect_left as bl
from bisect import bisect_right as br
inp = lambda : int(input())
mi = lambda x=int: map(x, input().split())
li = lambda x=int: list(mi(x))
lb = lambda x=int: list(map(x, input()))
ls = lambda : list(input())
bi = lambda n: bin(n).replace('0b', '')

def sbsq(a, s):
	i = 0
	for x in s:
		if i >= len(a):
			break
		if x == a[i]:
			i += 1
	return i == len(a)
yn = ['No', 'Yes']
YN = ['NO', 'YES']
YY = 'YES'
NN = 'NO'
yy = 'Yes'
nn = 'No'
alp = 'abcdefghijklmnopqrstuvwxyz'
inf = sys.maxsize
mod = 1000000007
from math import ceil, sqrt, gcd, log, comb
import heapq as hq

def main(kase):
	(n, k) = mi()
	a = li()
	a.sort()
	x = a[-k]
	print(comb(a.count(x), br(a, x) - (n - k)) % mod)
	pass
test_Cases = 1
test_Cases = inp()
for i in range(test_Cases):
	main(i)


from collections import Counter

def nCrModP(n, r, p):
	numerator = 1
	denominator = 1
	for i in range(r):
		numerator = numerator * (n - i) % p
		denominator = denominator * (i + 1) % p
	return numerator * pow(denominator, p - 2, p) % p
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	countArr = Counter(arr)
	countArr = sorted(list(countArr.items()))
	prevSum = 0
	for i in range(len(countArr) - 1, -1, -1):
		if prevSum + countArr[i][1] < k:
			prevSum += countArr[i][1]
		else:
			ans = nCrModP(countArr[i][1], k - prevSum, 10 ** 9 + 7)
			break
	print(ans)


mod = 10 ** 9 + 7

def calc(n, r):
	return fact[n] * pow(fact[r] * fact[n - r] % mod, mod - 2, mod) % mod
fact = [1, 1]
for i in range(2, 10000):
	fact.append(fact[-1] * i % mod)
for nt in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))[::-1]
	num = a[k - 1]
	for i in range(n):
		if a[i] == num:
			count = i
			break
	print(calc(a.count(num), k - count))


import math

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
test_cases = int(input())
for test_case in range(test_cases):
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	a.sort(reverse=True)
	_count = 0
	prev = a[0]
	prev_count = 0
	for num in a:
		_count += 1
		if num == prev:
			prev_count += 1
		else:
			prev = num
			prev_count = 1
		if _count >= k:
			break
	total = a.count(prev)
	print(nCr(total, prev_count) % (10 ** 9 + 7))


from math import comb
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	t = l[:k]
	T = set(t)
	d = dict()
	for i in l:
		d[i] = d.get(i, 0) + 1
	ans = 1
	for i in T:
		ans *= comb(d[i], t.count(i))
	print(ans % (10 ** 9 + 7))


from math import *
a = int(input())
for x in range(a):
	(d, e) = map(int, input().split())
	b = list(map(int, input().split()))
	b.sort(reverse=True)
	h = 0
	p = set([])
	ss = {}
	for y in range(e):
		p.add(b[y])
		if ss.get(b[y]) == None:
			ss[b[y]] = 1
		else:
			ss[b[y]] += 1
	t = {}
	for y in range(d):
		if b[y] in p:
			if t.get(b[y]) == None:
				t[b[y]] = 1
			else:
				t[b[y]] += 1
	l = 1
	for y in t:
		l *= comb(t[y], ss[y])
	print(l % (10 ** 9 + 7))


from math import comb
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = k
	l = list(map(int, input().split()))
	tot = 1
	for i in range(n):
		d = max(l)
		f = l.count(d)
		for a in range(f):
			l.remove(d)
		k = k - f
		if k == 0:
			print(1)
			break
		elif k < 0:
			k = k + f
			print(comb(f, k) % (1000000000 + 7))
			break


from math import comb
from sys import stdin
input = stdin.readline
MOD = 10 ** 9 + 7

def solve():
	(n, k) = [int(x) for x in input().split()]
	a = [0] + [int(x) for x in input().split()]
	a.sort()
	N = a.count(a[-k])
	M = a[-k:].count(a[-k])
	print(comb(N, M) % MOD)
for _ in range(int(input())):
	solve()


from itertools import combinations
from math import comb
testcase = int(input())

def enter():
	rseq = input()
	rseq = rseq.split(' ')
	rseq = list(map(int, rseq))
	return rseq
while testcase:
	c = 0
	e = 0
	f = 0
	hire = enter()
	follower = enter()
	follower.sort(reverse=True)
	for i in follower:
		if i >= follower[hire[1] - 1]:
			f += 1
		if i > follower[hire[1] - 1]:
			e += 1
	left = hire[1] - e
	j = f - e
	c = 1
	if left > 0:
		c = comb(j, left)
	c = c % 1000000007
	print(c)
	testcase -= 1


import math

def nCr(n, r):
	f = math.factorial
	return f(n) // (f(r) * f(n - r))
for iii in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	xx = arr.count(arr[k - 1])
	c = 0
	for item in arr[:k]:
		if item == arr[k - 1]:
			c += 1
	ans = nCr(xx, c)
	print(ans % (10 ** 9 + 7))


import sys
input = sys.stdin.readline

def make_nCr_mod(max_n=2 * 10 ** 5, mod=10 ** 9 + 7):
	max_n = min(max_n, mod - 1)
	(fact, inv_fact) = ([0] * (max_n + 1), [0] * (max_n + 1))
	fact[0] = 1
	for i in range(max_n):
		fact[i + 1] = fact[i] * (i + 1) % mod
	inv_fact[-1] = pow(fact[-1], mod - 2, mod)
	for i in reversed(range(max_n)):
		inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod

	def nCr_mod(n, r):
		res = 1
		while n or r:
			(a, b) = (n % mod, r % mod)
			if a < b:
				return 0
			res = res * fact[a] % mod * inv_fact[b] % mod * inv_fact[a - b] % mod
			n //= mod
			r //= mod
		return res
	return nCr_mod
nCk = make_nCr_mod(1000, mod=10 ** 9 + 7)
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()), reverse=True)
	smallest = a[k - 1]
	left = 0
	i = k - 2
	while i >= 0 and a[i] == smallest:
		i -= 1
		left += 1
	right = 0
	i = k
	while i < n and a[i] == smallest:
		i += 1
		right += 1
	print(nCk(left + right + 1, left + 1))


from bisect import bisect_left, bisect_right
from math import factorial
mod = 10 ** 9 + 7

def comb(n, k):
	x = factorial(n)
	y = factorial(k)
	z = factorial(n - k)
	return x // y // z % mod

def solve(k, arr):
	arr.sort()
	N = len(arr)
	first = N - k
	x = arr[first]
	right = bisect_right(arr, x)
	left = bisect_left(arr, x)
	p = right - first
	n = right - left
	return comb(n, p)
for _ in range(int(input())):
	(_, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(solve(k, arr))


import math
t = int(input())
ans = []
while t != 0:
	t = t - 1
	(n, k) = map(int, input().split(' '))
	li2 = list(map(int, input().split(' ')))
	li2.sort(reverse=True)
	el = li2[k - 1]
	cnt = li2.count(el)
	idx1 = li2.index(el)
	pick = k - idx1
	ncr = math.factorial(cnt) // (math.factorial(pick) * math.factorial(cnt - pick))
	ans.append(ncr)
for i in ans:
	v = int(i % (10 ** 9 + 7))
	print(v)


from math import comb
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	followers = list(map(int, input().split()))
	lista = sorted(followers, reverse=True)
	c = lista.count(lista[k - 1])
	r = lista[:k].count(lista[k - 1])
	print(comb(c, r) % (10 ** 9 + 7))


import sys
input = sys.stdin.readline
getint = lambda : int(input())
getints = lambda : [int(a) for a in input().split()]

def solve():
	(n, k) = getints()
	a = getints()
	mod = 1000000007
	counts = [0 for i in range(n + 1)]
	for v in a:
		counts[v] += 1
	res = 1
	pool = 0
	for count in reversed(counts):
		if k > count:
			k -= count
		else:
			pool = count
			break
	if k >= pool // 2:
		k = pool - k
	for i in range(k):
		res = res * (pool - i) // (1 + i)
	print(res % mod)
t = getint()
for i in range(t):
	solve()


import collections, sys, functools, heapq, bisect
input = sys.stdin.readline
mod = 10 ** 9 + 7

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	a.sort()
	ans = 0
	y = bisect.bisect_right(a, a[-k])
	x = bisect.bisect_left(a, a[-k])
	num = y - x
	ele = y - (n - k)
	numerator = 1
	denominator = 1
	for i in range(ele):
		numerator *= num - i
		numerator %= mod
		numerator *= modInverse(i + 1, mod)
	print(numerator % mod)


from itertools import groupby
from math import factorial
t = int(input())
for i in range(t):
	(n, k) = [int(v) for v in input().split()]
	w = [int(v) for v in input().split()]
	c = groupby(sorted(w))
	c = [[j[0], len(list(j[1]))] for j in c]
	while k and k >= c[-1][1]:
		k -= c.pop()[1]
	if k:
		z = c.pop()[1]
		print(factorial(z) // (factorial(k) * factorial(z - k)) % (10 ** 9 + 7))
	else:
		print(1)


from math import factorial
R = lambda : list(map(int, input().split()))

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))
mod = 10 ** 9 + 7
for _ in range(int(input())):
	(n, k) = R()
	a = R()
	counter = {}
	for i in a:
		counter[i] = counter.get(i, 0) + 1
	keys = sorted(counter)[::-1]
	h = 0
	way = 0
	for f in keys:
		if h + counter[f] < k:
			h += counter[f]
		else:
			way += ncr(counter[f], k - h)
			break
	print(way % mod)


MOD = 10 ** 9 + 7

def factorial(n):
	ans = 1
	for i in range(2, n + 1):
		ans = ans * i % MOD
	return ans

def C(n, k):
	nn = factorial(n)
	kk = 1
	for i in range(2, k + 1):
		kk = kk * pow(i, MOD - 2, MOD) % MOD
	nk = 1
	for i in range(2, n - k + 1):
		nk = nk * pow(i, MOD - 2, MOD) % MOD
	return nn * kk * nk % MOD
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	cnt1 = 0
	cnt2 = 0
	for i in range(0, k):
		if a[i] == a[k - 1]:
			cnt1 += 1
	for i in range(k, n):
		if a[i] == a[k - 1]:
			cnt2 += 1
	print(C(cnt1 + cnt2, cnt2))


import math
import sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
mod1 = 1000000007
mod2 = 998244353
from collections import defaultdict, Counter
fact = [1] * 1001
for i in range(1, 1001):
	fact[i] = fact[i - 1] * i % mod1
for _ in range(I()):
	(n, k) = M()
	a = sorted(L(), reverse=True)
	req = defaultdict(lambda : 0)
	for i in a:
		if k == 0:
			break
		req[i] += 1
		k -= 1
	count = Counter(a)
	ans = 1
	for i in req:
		x = count[i]
		y = req[i]
		num1 = fact[x]
		den1 = fact[y]
		den2 = fact[x - y]
		ans = ans * num1 % mod1 * pow(den1, -1, mod1) * pow(den2, -1, mod1) % mod1
	print(ans)


def fact(x):
	if x == 0:
		return 1
	if x == 1:
		return 1
	else:
		return x * fact(x - 1)
import math
T = int(input())
for t in range(T):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort(reverse=True)
	p = K - 1
	c = 1
	pnt = p
	for i in range(p + 1, N, 1):
		if A[p] != A[i]:
			break
		else:
			c += 1
	for i in range(p - 1, -1, -1):
		if A[p] != A[i]:
			break
		else:
			c += 1
			pnt -= 1
	done = pnt
	req = K - done
	ans = math.comb(c, req)
	ans = ans % 1000000007
	print(ans)


from math import comb

def main(n, k, s):
	s.sort()
	t = max(s)
	prod = 1
	arr = [0 for i in range(t + 1)]
	for i in range(n):
		arr[s[i]] += 1
	for i in range(t, 0, -1):
		if k == 0 or k < 0:
			break
		m = arr[i]
		if m == 0:
			continue
		if k >= m:
			k = k - m
			continue
		else:
			p = comb(m, k)
			prod = prod * p
			k = k - m
	return prod % 1000000007
m = int(input())
for _ in range(m):
	(n, k) = map(int, input().split())
	s = list(map(int, input().strip().split()))
	print(main(n, k, s))


from itertools import repeat, groupby

def line():
	return map(int, input().split())

def num():
	return int(input())

def nfunc(f, n, *args, **kwargs):
	return (f(*args, **kwargs) for _ in repeat(None, n))
t = num()
for _ in repeat(None, t):
	(n, k) = line()
	blogs = [len(list(g)) for (_, g) in groupby(sorted(line())[::-1])]
	ans = 1
	for m in blogs:
		if k <= m:
			for i in range(1, k + 1):
				ans *= m - k + i
			for i in range(1, k + 1):
				ans //= i
			break
		else:
			k -= m
	print(ans % (10 ** 9 + 7))


import math
import sys
input = sys.stdin.readline
from collections import Counter, defaultdict, deque
MAX_N = 1007
MOD = 10 ** 9 + 7

def modInverse(a, p):
	return pow(a, p - 2, p)
fact = [1]
for i in range(1, MAX_N + 1):
	fact.append(fact[-1] * i % MOD)
invFact = [0] * (MAX_N + 1)
invFact[MAX_N] = modInverse(fact[MAX_N], MOD)
for i in range(MAX_N - 1, -1, -1):
	invFact[i] = invFact[i + 1] * (i + 1) % MOD
inv = [0] * (MAX_N + 1)
for i in range(1, MAX_N + 1):
	inv[i] = fact[i - 1] * invFact[i] % MOD

def nCr(n, r):
	if n < r:
		return 0
	return fact[n] * invFact[r] * invFact[n - r] % MOD

def f(n, k, a):
	l = list(set(a))
	l.sort(reverse=True)
	c = Counter(a)
	el = 0
	for i in range(len(l)):
		el += c[l[i]]
		if el >= k:
			el -= c[l[i]]
			last = i
			break
	r = l[last]
	co = c[r]
	return nCr(co, k - el)
t = int(input())
result = []
for i in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	result.append(f(n, k, a))
for i in range(t):
	print(result[i])


from math import factorial

def nCk(n, k):
	return factorial(n) // (factorial(k) * factorial(n - k))
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	worst = a[k - 1]
	count = a.count(worst)
	picked = 0
	for i in a:
		if i == worst:
			break
		picked += 1
	topick = k - picked
	ans = nCk(count, topick)
	print(ans % 1000000007)


import sys
from collections import Counter
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = sys.stdin.readline
t = 1
t = int(input())

def nCrModp(n, r, p):
	if r > n - r:
		r = n - r
	C = [0 for i in range(r + 1)]
	C[0] = 1
	for i in range(1, n + 1):
		for j in range(min(i, r), 0, -1):
			C[j] = (C[j] + C[j - 1]) % p
	return C[r]
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = Counter(a)
	a = sorted(c.keys(), reverse=True)
	for el in a:
		if c[el] < k:
			k -= c[el]
		else:
			ans = nCrModp(c[el], k, 10 ** 9 + 7)
			break
	print(ans)


mod = 10 ** 9 + 7

def ncr(a, b):
	c = 1
	for i in range(a, b, -1):
		c = c * i % mod
	d = 1
	for i in range(1, a - b + 1):
		d = d * i % mod
	d = pow(d, mod - 2, mod)
	return c * d % mod
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	d = {}
	for i in range(k):
		try:
			d[l[i]] += 1
		except:
			d[l[i]] = 1
	e = {}
	for i in l:
		try:
			e[i] += 1
		except:
			e[i] = 1
	ans = 1
	for i in d:
		ans = ans * ncr(e[i], d[i])
	print(ans)


def c2n(num, k):
	k = min(k, num - k)
	res = 1
	nm = 1
	dem = 1
	while k > 0:
		nm *= num
		dem *= k
		num -= 1
		k -= 1
	return nm // dem
t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	lt = [int(x) for x in input().split()]
	dt = {}
	st = list(set(lt))
	st = sorted(st, reverse=True)
	for x in lt:
		dt[x] = dt.get(x, 0) + 1
	i = 0
	ans = 1
	while m > 0:
		if dt[st[i]] <= m:
			m -= dt[st[i]]
		else:
			ans = c2n(dt[st[i]], m)
			m = 0
		i += 1
	print(ans % 1000000007)


import sys
import math
rl = lambda : list(map(int, sys.stdin.readline().split()))
for _ in range(int(input())):
	(n, k) = rl()
	A = rl()
	dic = {}
	for a in A:
		if a in dic:
			dic[a] += 1
		else:
			dic[a] = 1
	num = 0
	cnt = []
	for a in sorted(dic, reverse=True):
		if num >= k:
			break
		num += dic[a]
		cnt.append(dic[a])
	for b in cnt[:-1]:
		k -= b
	print(math.factorial(cnt[-1]) // (math.factorial(k) * math.factorial(cnt[-1] - k)) % (10 ** 9 + 7))


mod = 1000000007
fact = list()
fact.append(1)
for i in range(1, 1001):
	fact.append(fact[len(fact) - 1] * i)

def C(n, k):
	return fact[n] // fact[k] // fact[n - k]

def solve():
	s = input().split()
	n = int(s[0])
	k = int(s[1]) - 1
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	i = k
	j = k
	while i > -1 and a[i] == a[k]:
		i -= 1
	while j < n and a[j] == a[k]:
		j += 1
	res = C(j - i - 1, k - i) % mod
	print(res)
t = int(input())
while t:
	solve()
	t -= 1


import sys, getpass
import math, random
import functools, itertools, collections, heapq, bisect
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
M9 = 10 ** 9 + 7
MAXINT = sys.maxsize
OFFLINE_TEST = getpass.getuser() == 'hkmac'

def log(*args):
	if OFFLINE_TEST:
		print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)

def solve(*args):
	if OFFLINE_TEST:
		log('----- solving ------')
		log(*args)
		log('----- ------- ------')
	return solve_(*args)

def read_matrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def read_strings(rows):
	return [input().strip() for _ in range(rows)]

@functools.lru_cache(maxsize=None)
def choose(n, r, p=M9):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def solve_(lst, k):
	lst = sorted(lst)[::-1]
	chosen = lst[:k]
	return choose(lst.count(chosen[-1]), chosen.count(chosen[-1]), M9)
for case_num in range(int(input())):
	(_, k) = list(map(int, input().split()))
	lst = list(map(int, input().split()))
	res = solve(lst, k)
	print(res)