Given a set of  N  natural numbers 1,2,3........N and Q query.For each query you have to calculate the total number of subset in which  Ith.
number of set come at Kth postion.Elements of every subset should be in sorted order.
The answer could  be very large so you have to print answer modulo 1e9+7.


-----Input:-----
- The first line of input cotains a single integer T denoting the number of test cases.
- For every test case it contains two number N and Q.
- Next Q line contains two number I and K.

-----Output:-----
For each test case print required answer.

-----Constraints and Subtasks:-----
- 1<=T<=5
- 1<=N, K<=4000
- 1<=Q<=1000000
Subtask 3: 5 points
- 1<=T<=5
- 1<=N, K<=16
- 1<=Q<=1000
Subtask 1: 25 points
- T=1
- 1<=N, K<=4000
- 1<=Q<=100000
Subtask 2: 70 points
- Original Constraints.

-----Example:-----
Input:

1

3 3

1 2

2 1

3 2

Output:

0

2

2

-----Explanation:-----
For N=3

total subsets are:

{1}

{2}

{3}

{1,2}

{1,3}

{2,3}

{1,2,3}

Now we can see that for I=1 and K=2 there is no subset in which 1 come at 2nd position so the answer is Zero for that query.

For 2nd query I=2 and K=1 there are two subset i.e {2,3} and {2} in which 2 come at 1st position.

Same for 3rd querry there is two subset i.e{1,3} and {2,3}.

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
import math
f = math.factorial
for u in range(eval(input())):
	(n, q) = list(map(int, input().split()))
	for j in range(q):
		(i, k) = list(map(int, input().split()))
		if k > i:
			c = 0
			print(c)
		else:
			a = 2 ** (n - i)
			b = 1
			d = int(i - 1)
			e = 1
			h = 1
			g = 1
			if k - 1 > i - k:
				for z in range(i - k):
					b = b * d
					d = d - 1
					e = e * h
					h = h + 1
				b = b / e
			else:
				for z in range(k - 1):
					b = b * d
					d = d - 1
					e = e * g
					g = g + 1
				b = b / e
			c = a * b
			c = c % 1000000007
			print(c)


mm = 1000000007
MAXN = 4001
comb = [[0] * MAXN]
comb[0][0] = 1
for i in range(1, MAXN):
	comb.append([0] * MAXN)
	comb[i][0] = 1
	for j in range(1, i + 1):
		comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1]
		comb[i][j] %= mm
p2 = [1, 2]
for i in range(2, 4001):
	p2.append(p2[-1] * 2 % mm)
t = int(input())
while t > 0:
	(n, m) = [int(x) for x in input().split()]
	while m > 0:
		(a, b) = [int(x) for x in input().split()]
		if b > a:
			print(0)
		else:
			r = comb[a - 1][b - 1]
			print(r * p2[n - a] % mm)
		m -= 1
	t -= 1


mm = 1000000007

def pow1(a, b, MOD):
	x = 1
	y = a
	while b > 0:
		if b % 2 == 1:
			x = x * y
			if x > MOD:
				x %= MOD
		y = y * y
		if y > MOD:
			y %= MOD
		b = b / 2
	return x

def abc(a, b):
	c = 1
	d = 1
	b = min(b, a - b)
	for i in range(b):
		c = c * a
		c = c / (i + 1)
		a -= 1
	return c % mm
p2 = [1, 2]
for i in range(2, 4001):
	p2.append(p2[-1] * 2 % mm)
t = int(input())
while t > 0:
	(n, m) = [int(x) for x in input().split()]
	while m > 0:
		(a, b) = [int(x) for x in input().split()]
		if b > a:
			print(0)
		else:
			r = abc(a - 1, b - 1)
			print(r * p2[n - a] % mm)
		m -= 1
	t -= 1


mm = 1000000007

def abc(a, b):
	c = 1
	d = 1
	for i in range(b):
		c = c * a % mm
		a -= 1
		d = d * (i + 1)
	return c * pow(d, mm - 2, mm) % mm
t = int(input())
while t > 0:
	(n, m) = [int(x) for x in input().split()]
	while m > 0:
		(a, b) = [int(x) for x in input().split()]
		if b > a:
			print(0)
		else:
			r = abc(a - 1, b - 1)
			print(r * pow(2, n - a, mm) % mm)
		m -= 1
	t -= 1


def fast_ncr(n, r):
	res = 1
	for i in range(1, r + 1):
		res *= n - r + i
		res /= i
	return res

def fast_exp(base, e):
	res = 1
	while e > 0:
		if e % 2 == 1:
			res = res * base % 1000000007
		base = base * base % 1000000007
		e /= 2
	return res % 1000000007
for t in range(int(input())):
	(n, q) = list(map(int, input().split()))
	for Q in range(q):
		(i, j) = list(map(int, input().split()))
		i -= 1
		j -= 1
		if i < j:
			print(0)
		else:
			print(fast_ncr(i, j) * fast_exp(2, n - i - 1) % 1000000007)


def modInv(b, p):
	return pow(b, p - 2, p)

def modNcr(n, r, p):
	fact = [1] * (n + 1)
	for i in range(1, n + 1):
		fact[i] = fact[i - 1] * i % p
	return fact[n] * (modInv(fact[r], p) * modInv(fact[n - r], p)) % p % p

def f(n, q):
	p = 10 ** 9 + 7
	for i in range(q):
		(l, k) = list(map(int, input().split()))
		if l < k:
			print(0)
		else:
			temp = pow(2, n - l, p) * modNcr(l - 1, k - 1, p) % p
			print(temp % (10 ** 9 + 7))
t = int(input())
for i in range(t):
	(n, q) = list(map(int, input().split()))
	f(n, q)


import sys
z = 10 ** 9 + 7
cachencr = {}
cachepow = {}
fact = []
fact.append(1)
for i in range(1, 4000):
	fact.append(i * fact[i - 1] % z)

def factorialMod(n):
	ans = 1
	for i in range(1, n + 1):
		ans = ans * i % z
	return ans % z

def nCr(n, r):
	if r > n:
		return 0
	key = n + r * 4001
	if key in cachencr:
		return cachencr[key]
	else:
		cachencr[key] = fact[n] * pow(fact[r] * fact[n - r], z - 2, z) % z
		return cachencr[key]

def powc(n):
	if n in cachepow:
		return cachepow[n]
	else:
		cachepow[n] = pow(2, n, z)
		return cachepow[n]
for _ in range(0, int(input())):
	(n, q) = list(map(int, input().split()))
	for __ in range(0, q):
		(i, k) = list(map(int, sys.stdin.readline().split()))
		a = nCr(i - 1, k - 1)
		b = powc(n - i)
		print(a * b % z)


z = 10 ** 9 + 7
fact = []
fact.append(1)
for i in range(1, 4000):
	fact.append(i * fact[i - 1] % z)

def factorialMod(n):
	ans = 1
	for i in range(1, n + 1):
		ans = ans * i % z
	return ans % z

def nCr(n, r):
	if r > n:
		return 0
	return fact[n] * pow(fact[r] * fact[n - r], z - 2, z) % z
for _ in range(0, int(input())):
	(n, q) = list(map(int, input().split()))
	for __ in range(0, q):
		(i, k) = list(map(int, input().split()))
		a = nCr(i - 1, k - 1)
		b = pow(2, n - i, z)
		print(a * b % z)


fact = [1]

def factorial(n):
	l = len(fact)
	i = n - l
	if i < 1:
		i = 0
	for x in range(i + 1):
		fact.append(fact[-1] * l)
		l += 1
	return fact[n]

def nCr(n, r):
	return factorial(n) / factorial(r) / factorial(n - r) % 1000000007

def fast_exp(base, e):
	res = 1
	while e > 0:
		if e % 2 == 1:
			res = res * base % 1000000007
		base = base * base % 1000000007
		e /= 2
	return base * res % 1000000007
for t in range(int(input())):
	(n, q) = list(map(int, input().split()))
	for Q in range(q):
		(i, j) = list(map(int, input().split()))
		i -= 1
		j -= 1
		if i < j:
			print(0)
		else:
			print(nCr(i, j) * 2 ** (n - i - 1) % 1000000007)


def nCr(n, r):
	if n < r:
		return 0
	M = 10 ** 9 + 7
	ret = fact[n] * pow(fact[r], M - 2, M) * pow(fact[n - r], M - 2, M)
	return ret % M
MOD = 10 ** 9 + 7
fact = [1] * 4001
for i in range(1, 4001):
	fact[i] = fact[i - 1] * i % MOD
for t in range(eval(input())):
	(n, q) = list(map(int, input().split()))
	for qq in range(q):
		(i, k) = list(map(int, input().split()))
		print(nCr(i - 1, k - 1) * pow(2, n - i, MOD) % MOD)