Jim enters a candy shop which has N different types of candies, each candy is of the same price. Jim has enough money to buy K candies. In how many different ways can he purchase K candies if there are infinite candies of each kind? 

Input Format 

The first line contains an integer T, the number of tests. 

This is followed by 2T lines which contain T tests: 

The first line (of each testcase) is an integer N and the second line (of each testcase) is an integer K.   

Output Format 

For each testcase, print the number of ways Jim can buy candies from the shop in a newline. If the answer has more than 9 digits, print the last 9 digits.  

Note 

This problem may expect you to have solved nCr Table

Constraints 

1 <= T <= 200 

1 <= N < 1000 

1 <= K < 1000  

Sample Input  

2
4
1
2
3

Sample Output  

4
4

Explanation 

There are 2 testcases, for the first testcase we have N = 4 and K = 1, as Jim can buy only 1 candy, he can choose to buy any of the 4 types of candies available. Hence, his answer is 4.
For the 2nd testcase, we have N = 2 and K = 3, If we name two chocolates as a and b, he can buy 

aaa bbb aab abb 

chocolates, hence 4.

Difficulty: MEDIUM
Tags: Mathematics

Starter code:

Solutions:
def nCr(n, r):
	if n - r < r:
		return nCr(n, n - r)
	rt = 1
	for i in range(1, r + 1):
		rt = rt * (n - i + 1) // i
	return rt
t = int(input())
for i in range(t):
	k = int(input())
	n = int(input())
	print(nCr(n + k - 1, n) % 1000000000)


import math
f = math.factorial
t = int(input())
for x in range(0, t):
	n = int(input())
	k = int(input())
	print(f(n + k - 1) // (f(k) * f(n - 1)) % 1000000000)


rem = 10 ** 9
T = int(input())
vals = []
maxTop = 0
for i in range(T):
	N = int(input())
	K = int(input())
	vals.append((N, K))
	top = N + K - 1
	if top > maxTop:
		maxTop = top
comb = [[1, 1]]
for i in range(1, maxTop):
	comb.append([1])
	for j in range(i):
		comb[i].append((comb[i - 1][j] + comb[i - 1][j + 1]) % rem)
	comb[i].append(1)
for i in vals:
	print(comb[i[0] + i[1] - 2][i[1]])


import math
T = int(input())
for i in range(T):
	N = int(input())
	K = int(input())
	print(math.factorial(K + N - 1) // (math.factorial(K) * math.factorial(N - 1)) % 1000000000)


def main():
	matrix = 1001 * [None]
	for i in range(1001):
		matrix[i] = (i + 1) * [None]
	matrix[0][0] = 1
	matrix[1][0] = 1
	matrix[1][1] = 1
	for i in range(1001):
		for j in range(i + 1):
			if j == 0:
				matrix[i][j] = 1
			elif j == i:
				matrix[i][j] = 1
			else:
				matrix[i][j] = matrix[i - 1][j] + matrix[i - 1][j - 1]
	t = int(input())
	for i in range(t):
		n = int(input())
		k = int(input())
		print(matrix[n + k - 1][k] % 1000000000)
main()


import sys

def next_int():
	return int(sys.stdin.readline())
choice_memo = {}
max_N = 1000
for n in range(1, max_N):
	choice_memo[n, 1] = n
	choice_memo[n, 2] = int(n * (n + 1) / 2)

def choice(n, k):
	r = choice_memo.get((n, k), None)
	if r:
		return r
	elif n == 1:
		return 1
	else:
		choice_memo[n, k] = (choice(n - 1, k) % 10 ** 9 + choice(n, k - 1) % 10 ** 9) % 10 ** 9
		return choice_memo[n, k]
T = next_int()
for _ in range(T):
	N = next_int()
	K = next_int()
	print(choice(N, K))


from math import factorial as f
for i in range(int(input())):
	n = int(input())
	k = int(input())
	print(f(n + k - 1) // (f(k) * f(n - 1)) % 1000000000)


T = int(input())
C = [[1], [1, 1]]
for i in range(1, 1000):
	l = len(C[i])
	row = [1] + [(a + b) % 1000000000 for (a, b) in zip(C[i][:l - 1], C[i][1:])] + [1]
	C.append(row)
for i in range(T):
	N = int(input())
	K = int(input())
	answer = 0
	for j in range(min(N, K)):
		answer += C[K - 1][j] * C[N][j + 1]
		answer %= 1000000000
	print(answer)


Ns = [[0 for x in range(0, 1000)]]
for y in range(1, 1000):
	n = [1]
	for x in range(1, 1000):
		n.append(n[-1] + Ns[-1][x])
	Ns.append(n)
T = int(input())
for t in range(0, T):
	N = int(input())
	K = int(input())
	print(Ns[N][K] % 10 ** 9)


import itertools, sys
T = int(sys.stdin.readline())
pascal = [[1], [1, 1]]
while len(pascal) < 1000:
	row = [(pascal[-1][i] + pascal[-1][i + 1]) % 10 ** 9 for i in range(len(pascal) - 1)]
	pascal.append([1] + row + [1])
pascal = [list(filter(None.__ne__, x)) for x in itertools.zip_longest(*pascal)]
for _ in range(T):
	N = int(sys.stdin.readline())
	K = int(sys.stdin.readline())
	print(pascal[N - 1][K])


from operator import mul
from functools import reduce
from fractions import Fraction

def nCk(n, k):
	return int(reduce(mul, (Fraction(n - i, i + 1) for i in range(k)), 1))
caseCnt = int(input())
for caseNr in range(caseCnt):
	n = int(input())
	k = int(input())
	print(nCk(k + n - 1, n - 1) % 10 ** 9)


class table:

	def __init__(self):
		self.table = [[1], [1]]
		self.length = 1

	def __getitem__(self, index):
		for i in range(self.length, index):
			self.table.append([1] + [(self.table[i][j] + self.table[i][j + 1]) % 10 ** 9 for j in range(i - 1)] + [1])
			self.length += 1
		return self.table[index]
import sys
next(sys.stdin)
nCr = table()
try:
	while True:
		N = int(next(sys.stdin).strip())
		K = int(next(sys.stdin).strip())
		print(sum((nCr[N + 1][n] * nCr[K][n - 1] for n in range(1, min(N, K) + 1))) % 10 ** 9)
except:
	pass


numtests = int(input())
tests = [(int(input()), int(input())) for x in range(numtests)]
item = [[1]]
for x in range(1, 1000):
	new = []
	previous = item[x - 1]
	k = len(previous) + 1
	for i in range(k):
		j = i - 1
		t = i
		if j < 0:
			prev = 0
			next = previous[t]
		elif t > len(previous) - 1:
			next = 0
			prev = previous[j]
		else:
			prev = previous[j]
			next = previous[t]
		new.append((prev + next) % 1000000000)
	item.append(new)
for test in tests:
	n = test[0]
	k = test[1]
	answer = item[n + k - 1][k]
	print(answer)


T = int(input())
ks = []
ns = []
for _ in range(T):
	ns.append(int(input()))
	ks.append(int(input()))
max_n_k = max(ns) + max(ks)
table = [[1] * (i + 1) for i in range(max_n_k + 1)]
for n in range(2, max_n_k + 1):
	for k in range(1, n):
		table[n][k] = (table[n - 1][k - 1] + table[n - 1][k]) % 10 ** 9
for (k, n) in zip(ks, ns):
	print(table[k + n - 1][k])


maxn = 1000
modc = 1000000000
ncrtable = [[1], [1, 1]]
for n in range(2, maxn):
	ncrtable.append([1] + [(ncrtable[-1][i] + ncrtable[-1][i + 1]) % modc for i in range(len(ncrtable[-1]) - 1)] + [1])
t = int(input())
for _ in range(t):
	(n, k) = (int(input()), int(input()))
	print(ncrtable[n - 1 + k][n - 1])


import math
t = int(input())
for t1 in range(t):
	n = int(input())
	k = int(input())
	print(math.factorial(n + k - 1) // (math.factorial(k) * math.factorial(n - 1)) % pow(10, 9))


from math import factorial as fact

def ncr(candies, money):
	return fact(candies + money - 1) // (fact(money) * fact(candies - 1))
for case in range(int(input())):
	ans = str(ncr(int(input()), int(input())))
	if len(ans) > 9:
		print(int(ans[-9:]))
	else:
		print(int(ans))


from math import *

def can(n, k):
	if n >= k:
		a = factorial(n) * factorial(k - 1)
		summ = 0
		for t in range(1, k + 1):
			summ = summ + int(a // (t * factorial(n - t) * factorial(k - t) * factorial(t - 1) ** 2))
	elif n < k:
		a = factorial(n) * factorial(k - 1)
		summ = 0
		for t in range(1, n + 1):
			summ = summ + int(a // (t * factorial(n - t) * factorial(k - t) * factorial(t - 1) ** 2))
	if len(str(summ)) <= 9:
		print(summ)
	elif len(str(summ)) > 9:
		print(int(str(summ)[len(str(summ)) - 9:]))
num = int(input())
lis = []
for i in range(1, num + 1):
	li = [int(input()), int(input())]
	lis.append(li)
for x in lis:
	can(x[0], x[1])


test = int(input())
for f in range(test):
	b = int(input())
	a = int(input())
	ans1 = 1
	for i in range(1, b):
		ans1 *= b + a - i
	ans2 = 1
	for i in range(1, b):
		ans2 *= i
	if len(str(ans1 // ans2)) > 8:
		print(int(str(ans1 // ans2)[-9:]))
	else:
		print(ans1 // ans2)


t = int(input())
tab = [[1, 1]]
for dfasf in range(t):
	n = int(input())
	k = int(input())
	n = n + k - 1
	for i in range(len(tab), n):
		tab.append([])
		for j in range(i + 2):
			if j == 0 or j == i + 1:
				tab[i].append(1)
			else:
				tab[i].append((tab[i - 1][j - 1] + tab[i - 1][j]) % 10 ** 9)
	print(tab[n - 1][k])


import math
f = math.factorial
t = int(input())
while t:
	n = int(input())
	k = int(input())
	print(f(n + k - 1) // (f(k) * f(n - 1)) % 1000000000)
	t -= 1


import math
t = int(input())
for i in range(t):
	n = int(input())
	k = int(input())
	ans = math.factorial(n + k - 1) // (math.factorial(n - 1) * math.factorial(k))
	if len(str(ans)) > 9:
		m = str(ans)
		print(int(m[len(m) - 9:len(m) + 1]))
	else:
		print(ans)


def create_generator():
	prev = [1, 1]
	while True:
		res = [prev[0]]
		for i in range(1, len(prev)):
			res.append((prev[i - 1] + prev[i]) % 1000000000)
		res.append(prev[len(prev) - 1])
		prev = res
		yield res

def cnk(k, n, memo, gen):
	for i in range(len(memo), n + 1):
		memo.append(next(gen))
	return memo[n][k]
known = [[1], [1, 1]]
generator = create_generator()
for _ in range(int(input().strip())):
	n = int(input().strip())
	k = int(input().strip())
	res = 0
	for i in range(1, min(n, k) + 1):
		res = (res + cnk(i, n, known, generator) * cnk(i - 1, k - 1, known, generator)) % 1000000000
	print(res)


from math import factorial as f

def nCr(n, r):
	return f(n) // f(r) // f(n - r)
for T in range(int(input())):
	(N, K) = (int(input()), int(input()))
	print(nCr(N + K - 1, K) % 10 ** 9)


from math import factorial as fact
t = int(input())
for _ in range(t):
	k = int(input().strip()) - 1
	n = int(input().strip()) + 1
	n = n + k - 1
	print(fact(n) // (fact(k) * fact(n - k)) % 10 ** 9)


import itertools, sys
T = int(sys.stdin.readline())
pascal = [[1], [1, 1]]
while len(pascal) < 1000:
	row = [(pascal[-1][i] + pascal[-1][i + 1]) % 10 ** 9 for i in range(len(pascal) - 1)]
	pascal.append([1] + row + [1])
pascal = [list(filter(None.__ne__, x)) for x in itertools.zip_longest(*pascal)]
for _ in range(T):
	N = int(sys.stdin.readline())
	K = int(sys.stdin.readline())
	print(pascal[N - 1][K])


import math
for _ in range(int(input())):
	n = int(input())
	k = int(input())
	print(math.factorial(k + n - 1) // (math.factorial(k) * math.factorial(n - 1)) % 10 ** 9)


from math import factorial

def nCr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))
numTests = int(input())
for test in range(numTests):
	n = int(input())
	k = int(input())
	print(nCr(n + k - 1, k) % 10 ** 9)


matr = [[0 for i in range(2001)] for j in range(2001)]
for i in range(0, 2001):
	matr[0][i] = matr[i][i] = 1
for i in range(2, 2001):
	for j in range(1, i):
		matr[i][j] = (matr[i - 1][j - 1] + matr[i - 1][j]) % 1000000000
t = int(input())
for k in range(0, t):
	x = int(input())
	y = int(input())
	print(matr[x + y][y + 1])


MOD = 10 ** 9

def f(n, k):
	(a, b) = (n, 1)
	res = a * b
	for i in range(1, k):
		a = a * (n - i) // (i + 1)
		b = b * (k - i) // i
		res = (res + a * b) % MOD
	return res
T = int(input())
for _ in range(T):
	N = int(input())
	K = int(input())
	print(f(N, K))


ncr = [[0] * (n + 1) for n in range(2001)]
for n in range(2001):
	ncr[n][0] = ncr[n][n] = 1
	for r in range(1, n):
		ncr[n][r] = (ncr[n - 1][r] + ncr[n - 1][r - 1]) % 1000000000
T = int(input())
for _ in range(T):
	N = int(input())
	K = int(input())
	print(ncr[N + K - 1][K])


def printar(a):
	x = ' '.join(map(str, a))
	print(x)

def modit(a):
	b = []
	for i in a:
		b.append(i % 1000000000)
	return b
t = int(input().strip())
max = 1
pas = [[], [1, 1]]
for tt in range(t):
	flavors = int(input().strip())
	candies = int(input().strip())
	n = candies + flavors - 1
	if n > max:
		for i in range(max, n + 1):
			nr = []
			old = 0
			for j in pas[max]:
				jj = old + j
				nr.append(jj)
				old = j
			nr.append(1)
			pas.append(nr)
			max += 1
	print(pas[n][candies] % 1000000000)


import math

def binomial(n, r):
	return math.factorial(n) // math.factorial(n - r) // math.factorial(r)
for _ in range(int(input())):
	n = int(input())
	k = int(input())
	print(binomial(n + k - 1, k) % 10 ** 9)


import itertools, sys
T = int(sys.stdin.readline())
pascal = [[1], [1, 1]]
while len(pascal) < 1000:
	row = [(pascal[-1][i] + pascal[-1][i + 1]) % 10 ** 9 for i in range(len(pascal) - 1)]
	pascal.append([1] + row + [1])
pascal = [list(filter(None.__ne__, x)) for x in itertools.zip_longest(*pascal)]
for _ in range(T):
	N = int(sys.stdin.readline())
	K = int(sys.stdin.readline())
	print(pascal[N - 1][K])


import itertools, sys
T = int(sys.stdin.readline())
pascal = [[1], [1, 1]]
while len(pascal) < 1000:
	row = [(pascal[-1][i] + pascal[-1][i + 1]) % 10 ** 9 for i in range(len(pascal) - 1)]
	pascal.append([1] + row + [1])
pascal = [list(filter(None.__ne__, x)) for x in itertools.zip_longest(*pascal)]
for _ in range(T):
	N = int(sys.stdin.readline())
	K = int(sys.stdin.readline())
	print(pascal[N - 1][K])


import math
t = int(input())
for ii in range(0, t):
	n = int(input())
	k = int(input())
	nkf = math.factorial(n + k - 1)
	kf = math.factorial(k)
	nf = math.factorial(n - 1)
	print(nkf // (kf * nf) % 1000000000)


import itertools, sys
T = int(sys.stdin.readline())
pascal = [[1], [1, 1]]
while len(pascal) < 1000:
	row = [(pascal[-1][i] + pascal[-1][i + 1]) % 10 ** 9 for i in range(len(pascal) - 1)]
	pascal.append([1] + row + [1])
pascal = [list(filter(None.__ne__, x)) for x in itertools.zip_longest(*pascal)]
for _ in range(T):
	N = int(sys.stdin.readline())
	K = int(sys.stdin.readline())
	print(pascal[N - 1][K])


P = []

def choose(n, k):
	if n == k or k == 0:
		return 1
	if P[n][k] != -1:
		return P[n][k]
	res = (choose(n - 1, k - 1) + choose(n - 1, k)) % 10 ** 9
	P[n][k] = res
	return res
P = [[-1 for y in range(2001)] for x in range(2001)]
t = int(input())
for z in range(t):
	n = int(input())
	k = int(input())
	print(choose(n + k - 1, n - 1))


comb = {}
for i in range(2001):
	comb[i, 0] = 1
	comb[i, i] = 1
	for j in range(1, i):
		comb[i, j] = (comb[i - 1, j] + comb[i - 1, j - 1]) % 10 ** 9

def jim_candy(n, k):
	return comb[n + k - 1, k]
numTrials = int(input())
for i in range(numTrials):
	n = int(input())
	k = int(input())
	print(jim_candy(n, k))


import math
t = int(input())
for i in range(t):
	n = int(input())
	k = int(input())
	s = str(math.factorial(n + k - 1) // math.factorial(n - 1) // math.factorial(k))
	if len(s) > 9:
		k = 9
		while s[len(s) - k] == '0':
			k -= 1
		result = s[len(s) - k:]
		print(result)
	else:
		print(s)


import math
t = int(input())
for _ in range(t):
	N = int(input())
	R = int(input())
	N_R_1 = math.factorial(N + R - 1)
	r = math.factorial(R)
	N_1 = math.factorial(N - 1)
	result = N_R_1 // (r * N_1)
	if len(str(result)) > 9:
		print(result % 10 ** 9)
	else:
		print(result)


from operator import mul
from fractions import Fraction
from functools import reduce

def nCk(n, k):
	return int(reduce(mul, (Fraction(n - i, i + 1) for i in range(k)), 1))
T = int(input())
for _ in range(T):
	N = int(input())
	K = int(input())
	print(nCk(N + K - 1, K) % 1000000000)


t = int(input())
for i in range(t):
	n = int(input())
	r = int(input())
	ans = 1
	for j in range(1, r + 1):
		ans = ans * (n + j - 1) // j
	print(ans % 1000000000)


def pascal_triangle(n, mod):
	pascal = [x[:] for x in [[0] * (n + 1)] * (n + 1)]
	pascal[0][0] = 1
	for i in range(1, n + 1):
		pascal[i][0] = 1
		for j in range(1, i + 1):
			pascal[i][j] = (pascal[i - 1][j] + pascal[i - 1][j - 1]) % mod
	return pascal
triangle = pascal_triangle(2000, pow(10, 9))
for t in range(int(input().strip())):
	N = int(input().strip())
	K = int(input().strip())
	print(triangle[N + K - 1][K])


def factorial(n):
	num = 1
	while n >= 1:
		num = num * n
		n = n - 1
	return num
size = int(input())
for i in range(size):
	N = int(input())
	K = int(input())
	res = factorial(N + K - 1) // factorial(K)
	res = res // factorial(N - 1)
	res = res % 10 ** 9
	print('%d' % res)


from math import factorial

def mod_fact(n, p):
	out = 1
	for i in range(1, n + 1):
		out = int(out * i) % p
	return out

def mod_exp(a, b, p):
	r = 0
	if b == 0:
		return 1
	elif b % 2 == 0:
		return mod_exp(a, b / 2, p) ** 2 % p
	else:
		return a * mod_exp(a, b - 1, p) % p

def ncr(n, r, p):
	out = factorial(n) // (factorial(n - k) * factorial(k))
	return out
T = int(input())
for t in range(0, T):
	n = int(input())
	k = int(input())
	p = 1000000000
	print(ncr(n + k - 1, k, p) % p)


MOD = 1000000000
NUM_ROWS = 1001
nCr = [0] * NUM_ROWS
for row in range(NUM_ROWS):
	nCr[row] = []
	for col in range(row + 1):
		nCr[row].append(1 if col == 0 or col == row else (nCr[row - 1][col - 1] + nCr[row - 1][col]) % MOD)
for _ in range(int(input())):
	n = int(input())
	k = int(input())
	print(sum((nCr[n][i + 1] * nCr[k - 1][i] for i in range(min(n, k)))) % MOD)


import math

def fac(n):
	ret = 1
	for i in range(1, n + 1):
		ret *= i
	return ret

def buy(things, boxes):
	u = things + boxes - 1
	l = boxes - 1
	c = fac(u) // (fac(l) * fac(u - l))
	return int(c)
t = int(input())
for i in range(t):
	n = int(input())
	k = int(input())
	ans = buy(k, n)
	if ans >= 10 ** 9:
		ans = ans % 10 ** 9
	print(ans)


import itertools, sys
T = int(sys.stdin.readline())
pascal = [[1], [1, 1]]
while len(pascal) < 1000:
	row = [(pascal[-1][i] + pascal[-1][i + 1]) % 10 ** 9 for i in range(len(pascal) - 1)]
	pascal.append([1] + row + [1])
pascal = [list(filter(None.__ne__, x)) for x in itertools.zip_longest(*pascal)]
for _ in range(T):
	N = int(sys.stdin.readline())
	K = int(sys.stdin.readline())
	print(pascal[N - 1][K])


from math import factorial
m = 10 ** 9
for _ in range(int(input())):
	N = int(input())
	K = int(input())
	print(factorial(N + K - 1) // (factorial(K) * factorial(N - 1)) % 10 ** 9)


def extended_gcd(aa, bb):
	(lastremainder, remainder) = (abs(aa), abs(bb))
	(x, lastx, y, lasty) = (0, 1, 1, 0)
	while remainder:
		(lastremainder, (quotient, remainder)) = (remainder, divmod(lastremainder, remainder))
		(x, lastx) = (lastx - quotient * x, x)
		(y, lasty) = (lasty - quotient * y, y)
	return (lastremainder, lastx * (-1 if aa < 0 else 1), lasty * (-1 if bb < 0 else 1))

def modinv(a, m):
	(g, x, y) = extended_gcd(a, m)
	if g != 1:
		raise ValueError
	return x % m

def modBinomial(n, k, p):
	numerator = 1
	for i in range(k):
		numerator = numerator * (n - i)
	denominator = 1
	for i in range(1, k + 1):
		denominator = denominator * i
	return numerator // denominator % p
mod = 10 ** 9
for _ in range(int(input())):
	N = int(input())
	K = int(input())
	print(modBinomial(N + K - 1, K, mod))


from math import factorial

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

def result(n, k):
	answer = nCk(n + k - 1, k)
	return answer % 10 ** 9

def main():
	t = int(input())
	for i in range(0, t):
		n = int(input())
		k = int(input())
		print(result(n, k))
main()


from math import factorial
r = 10 ** 9
n_tests = int(input())
for t in range(n_tests):
	n = int(input())
	k = int(input())
	print(factorial(k + n - 1) // (factorial(k) * factorial(n - 1)) % r)


matr = [[0 for i in range(1001)] for j in range(1001)]
for i in range(0, 1001):
	matr[0][i] = matr[i][i] = 1
for i in range(2, 1001):
	for j in range(1, i):
		matr[i][j] = (matr[i - 1][j - 1] + matr[i - 1][j]) % 1000000000
for each in range(int(input())):
	n = int(input())
	k = int(input())
	print(matr[n + k][n])


import itertools
pascal = [[1], [1, 1]]
while len(pascal) < 1000:
	row = [(pascal[-1][i] + pascal[-1][i + 1]) % 10 ** 9 for i in range(len(pascal) - 1)]
	pascal.append([1] + row + [1])
pascal = [list(filter(None.__ne__, x)) for x in itertools.zip_longest(*pascal)]
for T in range(int(input())):
	N = int(input())
	K = int(input())
	print(pascal[N - 1][K])


import itertools, sys
T = int(sys.stdin.readline())
pascal = [[1], [1, 1]]
while len(pascal) < 1000:
	row = [(pascal[-1][i] + pascal[-1][i + 1]) % 10 ** 9 for i in range(len(pascal) - 1)]
	pascal.append([1] + row + [1])
pascal = [list(filter(None.__ne__, x)) for x in itertools.zip_longest(*pascal)]
for _ in range(T):
	N = int(sys.stdin.readline())
	K = int(sys.stdin.readline())
	print(pascal[N - 1][K])


import math

def binom(x, y):
	if y == x:
		return 1
	elif y == 1:
		return x
	elif y > x:
		return 0
	else:
		a = math.factorial(x)
		b = math.factorial(y)
		c = math.factorial(x - y)
		div = a // (b * c)
		return div
for _ in range(int(input())):
	n = int(input())
	k = int(input())
	print(binom(n + k - 1, k) % 10 ** 9)


from math import factorial

def comb(n, k):
	return factorial(n) // (factorial(k) * factorial(n - k))
for _ in range(int(input())):
	N = int(input())
	K = int(input())
	print(comb(N + K - 1, K) % 1000000000)


import sys
f = sys.stdin
N = 1001
preval = [[1], [1, 1]]
for i in range(2, N):
	new = [1, i]
	for col in range(2, i):
		new += [int((preval[i - 1][col] + preval[i - 1][col - 1]) % 1000000000.0)]
	new += [1]
	preval.append(new)
T = int(f.readline())
for i in range(T):
	N = int(f.readline())
	k = int(f.readline())
	print(preval[N + k - 1][k])


import math

def main():
	test_count = int(input())
	for __ in range(test_count):
		(n, k) = (int(input()), int(input()))
		N = k + 1
		K = n - 1
		ans = math.factorial(N + K - 1) // (math.factorial(K) * math.factorial(N - 1))
		print(ans % 10 ** 9)
main()


maximal = 1001
mod = 10 ** 9
a = [[0 for a in range(maximal)] for b in range(maximal)]
for m in range(maximal):
	a[0][m] = 1
for n in range(maximal):
	for m in range(maximal):
		a[n][m] = (a[n - 1][m] + a[n][m - 1]) % mod
t = int(input())
for _ in range(t):
	n = int(input())
	m = int(input())
	print(a[n - 1][m])


import sys
import math
n = int(input().strip())
a = []
for a_i in range(2 * n):
	a_t = [int(a_temp) for a_temp in input().strip().split(' ')]
	a = a + a_t
for i in range(0, 2 * n, 2):
	m = a[i]
	k = a[i + 1]
	result = 1
	if m >= k + 1:
		for j in range(k):
			result = result * (m + k - 1 - j)
		result = int(result // math.factorial(k)) % 10 ** 9
	else:
		for j in range(m - 1):
			result = result * (m + k - 1 - j)
		result = int(result // math.factorial(m - 1)) % 10 ** 9
	print(result)


from math import factorial
for _ in range(int(input())):
	N = int(input())
	K = int(input())
	c = factorial(N + K - 1) // (factorial(K) * factorial(N - 1))
	print(c % 10 ** 9)


MAXN = 2005
MOD = 1000000000
nCr = [[0 for x in range(MAXN)] for i in range(MAXN)]

def Preprocess():
	nCr[0][0] = 0
	nCr[1][0] = 1
	nCr[1][1] = 1
	for i in range(2, MAXN):
		nCr[i][0] = 1
		for j in range(1, i + 1):
			nCr[i][j] = (nCr[i - 1][j - 1] + nCr[i - 1][j]) % MOD

def solve():
	N = int(input())
	K = int(input())
	ans = nCr[N + K - 1][N - 1]
	print(ans)

def main():
	Preprocess()
	t = int(input())
	while t > 0:
		solve()
		t -= 1
main()


def pascal(n, k, m1):
	if k == 0 or k == n or n == 0:
		return 1
	elif (n, k) in cache:
		return cache[n, k]
	else:
		value = (pascal(n - 1, k - 1, m1) + pascal(n - 1, k, m1)) % m1
		cache[n, k] = value
		return value
cache = {}
m1 = 1000000000
nTst = int(input())
for t1 in range(nTst):
	nn = int(input())
	k1 = int(input())
	print(pascal(nn + k1 - 1, k1, m1))


import math

def num_combinations(n, k):
	return math.factorial(n + k - 1) // (math.factorial(n - 1) * math.factorial(k)) % 10 ** 9
T = int(input())
for t_i in range(T):
	(N, K) = (int(input()), int(input()))
	print(num_combinations(N, K))


import math
MOD = 10 ** 9

def get_number_of_permutations(n, k):
	return math.factorial(k + n - 1) // (math.factorial(n - 1) * math.factorial(k))
t = int(input())
for _ in range(t):
	n = int(input())
	k = int(input())
	print(get_number_of_permutations(n, k) % MOD)


import functools
M = 10 ** 9

def f(a):
	return functools.reduce(lambda x, y: x * y, range(1, a + 1), 1)

def binom(a, b):
	return f(a) // (f(b) * f(a - b))
t = int(input())
for _ in range(t):
	n = int(input())
	k = int(input())
	print(binom(n + k - 1, k) % M)


def choose(n, k):
	r = 1
	for i in range(1, k + 1):
		r *= n - i + 1
		r //= i
	return r % 1000000000
t = int(input())
for i in range(t):
	n = int(input())
	k = int(input())
	print(choose(n + k - 1, n - 1))


import sys
line = 0
comb = {}
for i in range(1, 2000):
	comb[i] = {}
for i in range(1, 2000):
	for j in range(0, i + 1):
		if j == 0 or j == i:
			comb[i][j] = 1
		else:
			comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % 1000000000
for text in sys.stdin:
	if line > 0:
		if line % 2 == 1:
			n = int(text)
		else:
			k = int(text)
			print(comb[n + k - 1][k])
	line += 1


from math import factorial
for _ in range(int(input())):
	n = int(input())
	k = int(input())
	print(factorial(n + k - 1) // (factorial(k) * factorial(n - 1)) % 1000000000)


nCr = [[1]]
for i in range(1, 2000):
	nCr += [[1] + [(nCr[i - 1][j] + nCr[i - 1][j + 1]) % 10 ** 9 for j in range(i - 1)] + [1]]
t = int(input())
for _ in range(t):
	n = int(input())
	k = int(input())
	print(nCr[n + k - 1][n - 1])


import operator as op
from functools import reduce

def ncr(n, r):
	r = min(r, n - r)
	if r == 0:
		return 1
	numer = reduce(op.mul, range(n, n - r, -1))
	denom = reduce(op.mul, range(1, r + 1))
	return numer // denom
t = int(input())
for _ in range(t):
	n = int(input())
	k = int(input())
	x = ncr(n + k - 1, k)
	y = int(str(x)[-9:])
	print(y)


import math

def nCr(n, r):
	f = math.factorial
	return int(f(n) // f(r) // f(n - r))
for t in range(int(input())):
	N = int(input())
	K = int(input())
	print(nCr(N + K - 1, K) % 1000000000)


t = int(input())
while t:
	t -= 1
	(n, k) = (int(input()), int(input()))

	def binom(a, b):
		nt = 1
		for tt in range(min(b, a - b)):
			nt = nt * (a - tt) // (tt + 1)
		return nt
	print(binom(n + k - 1, k) % 1000000000)


bino = [[1]]
for xx in range(2000):
	cur = bino[-1]
	nex = cur + [0]
	for i in range(len(cur)):
		nex[i + 1] = (nex[i + 1] + cur[i]) % 1000000000
	bino.append(nex)
for xx in range(int(input())):
	n = int(input())
	k = int(input())
	n -= 1
	print(bino[n + k][k])


K = 10 ** 9
f = [[1 for i in range(1000)] for j in range(2000)]
for i in range(2, 2000):
	for j in range(1, min(i, 1000)):
		f[i][j] = (f[i - 1][j - 1] + f[i - 1][j]) % K
for _ in range(int(input())):
	n = int(input())
	k = int(input())
	print(f[k + n - 1][n - 1])


import math, functools, itertools

@functools.lru_cache(maxsize=None)
def fact(n):
	return math.factorial(n)

@functools.lru_cache(maxsize=None)
def newt(n, k):
	x = fact(n) // (fact(k) * fact(n - k))
	return x % 10 ** 9
for _ in range(int(input())):
	n = int(input())
	k = int(input())
	print(newt(n + k - 1, k) % 10 ** 9)


import math
test = int(input())
for i in range(test):
	nr = []
	for k in range(2):
		nr.append(int(input()))
	temp = nr[0] + nr[1] - 1
	temp2 = nr[0] - 1
	res = math.factorial(temp) // (math.factorial(nr[1]) * math.factorial(temp2))
	print(res % 1000000000)


t = int(input().strip())
table = [[1]]
for _ in range(2000):
	row = table[-1]
	nxt = [1]
	for i in range(1, len(row)):
		nxt += [(row[i - 1] + row[i]) % 10 ** 9]
	nxt += [1]
	table += [nxt]
for _ in range(t):
	n = int(input().strip())
	k = int(input().strip())
	print(table[n + k - 1][k])


from math import factorial
factorialTable = {}

def fact(x):
	if x in factorialTable:
		return factorialTable[x]
	else:
		factorialTable[x] = factorial(x)
		return factorialTable[x]
for _ in range(int(input())):
	n = int(input())
	k = int(input())
	print(fact(n + k - 1) // (fact(k) * fact(n - 1)) % 1000000000)


from collections import defaultdict
MOD = 10 ** 9
is_prime = [True] * 1005
primes = []
for i in range(2, 1001):
	if is_prime[i]:
		for j in range(i + i, 1001, i):
			is_prime[j] = False
		primes.append(i)

def factorial_prime_factors(x):
	d = defaultdict(int)
	for p in primes:
		curpow = p
		while curpow <= x:
			d[p] += x // curpow
			curpow *= p
	return d

def modchoose(n, k, m):
	num = factorial_prime_factors(n)
	den1 = factorial_prime_factors(k)
	den2 = factorial_prime_factors(n - k)
	acc = 1
	for p in primes:
		num[p] -= den1[p] + den2[p]
		acc = acc * p ** num[p] % m
	return acc
for _ in range(int(input())):
	N = int(input())
	K = int(input())
	print(modchoose(N + K - 1, K, MOD))


import sys
from math import factorial

def ncr(n, r):
	if n - r < r:
		r = n - r
	return factorial(n) // (factorial(r) * factorial(n - r))
t = int(input())
for i in range(t):
	n = int(input())
	k = int(input())
	print(ncr(n + k - 1, k) % 10 ** 9)


import math

def rep(n, k):
	c = n + k - 1
	res = math.factorial(c) // (math.factorial(k) * math.factorial(n - 1))
	return res % 10 ** 9
t = int(input())
factorial = math.factorial
if t >= 1 and t <= 200:
	for i in range(t):
		n = int(input())
		k = int(input())
		print(rep(n, k))


def ncr(n, r):
	ans = 1
	for i in range(r + 1, n + 1):
		ans *= i
	for i in range(1, n - r + 1):
		ans //= i
	return ans % 1000000000
T = int(input())
for _ in range(T):
	(N, K) = (int(input()), int(input()))
	print(ncr(N + K - 1, K))


def f(n):
	a = 1
	for i in range(1, n + 1):
		a *= i
	return a

def C(n, r):
	return f(n) // (f(n - r) * f(r))
t = int(input())
for i in range(t):
	(n, k) = (int(input()), int(input()))
	print(C(n + k - 1, k) % 10 ** 9)


import sys
from math import factorial
T = int(input().strip())
Ns = []
Ks = []
for i in range(T):
	Ns.append(int(input().strip()))
	Ks.append(int(input().strip()))
for i in range(T):
	N = Ns[i]
	K = Ks[i]
	print(factorial(N + K - 1) // factorial(N - 1) // factorial(K) % 10 ** 9)


import math
T = int(input())
for i in range(T):
	K = int(input())
	N = int(input())
	s = str(int(math.factorial(N + K - 1) // math.factorial(N) // math.factorial(N + K - 1 - N)))
	if len(s) > 9:
		print(int(s[-9:]))
	else:
		print(s)


def coef(k, prev):
	if k == 0 or k == len(prev):
		return 1
	return prev[k - 1] + prev[k]

def Cnk(n, k):
	if k > n / 2:
		k = n - k
	prev = []
	cur = []
	for r in range(0, n + 1):
		for c in range(0, r + 1):
			val = coef(c, prev)
			if r == n and c == k:
				return val
			cur.append(val)
			pass
		prev = cur
		cur = []
		pass
	return 0

def Cnk_rows(rows):
	n = 0
	r_map = {}
	for r in rows:
		r_map[r] = []
		n = max(n, r)
	prev = []
	cur = []
	for r in range(0, n + 1):
		for c in range(0, r + 1):
			val = coef(c, prev)
			cur.append(val)
			pass
		if r in r_map:
			r_map[r] = cur
		prev = cur
		cur = []
		pass
	result = {}
	for r in rows:
		result[r] = r_map[r]
	return result
import sys
mod = 10 ** 9
T = int(sys.stdin.readline())
data = []
degrees = []
for i in range(0, T):
	N = int(sys.stdin.readline())
	K = int(sys.stdin.readline())
	data.append([N + K - 1, K])
	degrees.append(N + K - 1)
rows = Cnk_rows(degrees)
for d in data:
	(n, k) = (d[0], d[1])
	print(rows[n][k] % mod)


from math import factorial
for _ in range(int(input())):
	(n, k) = (int(input()) - 1, int(input()))
	print(factorial(k + n) // factorial(k) // factorial(n) % 10 ** 9)


from math import factorial
for i in range(int(input())):
	n = int(input())
	k = int(input())
	ans = factorial(n + k - 1) // (factorial(n - 1) * factorial(k))
	print(ans % 1000000000)


from math import factorial
mod = 1000000000
t = int(input())

def choose(n, r):
	f = factorial
	return int(f(n) // f(r) // f(n - r) % mod)
for i in range(t):
	n = int(input())
	k = int(input())
	p = list(range(k))
	m = choose(n + k - 1, k)
	print(m)


import math as m
for _ in range(int(input())):
	n = int(input())
	k = int(input())
	N = n + k - 1
	print(m.factorial(N) // (m.factorial(k) * m.factorial(N - k)) % 10 ** 9)


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	r = int(input())
	print(factorial(n + r - 1) // (factorial(n - 1) * factorial(r)) % 1000000000)


trial = int(input())
for t in range(trial):
	case = [int(input())]
	case.append(int(input()))
	(answer, divide) = (1, 1)
	for (cnt, num) in enumerate(range(max(case[0] - 1, case[1]), case[0] + case[1] - 1)):
		answer *= num + 1
		divide *= cnt + 1
	else:
		print(answer // divide % 10 ** 9)


from math import factorial

def c(n, k):
	return factorial(n) // (factorial(n - k) * factorial(k))
t = int(input())
for _ in range(t):
	n = int(input())
	k = int(input())
	print(c(n + k - 1, k) % 1000000000)


modo = 10 ** 9

def rList(N, K):
	NparN = [[1] + [0] * K]
	NparN += list((list([1] + [0] * K) for _ in range(N)))
	for n in range(1, N + 1):
		for k in range(1, K + 1):
			NparN[n][k] = (NparN[n][k - 1] + NparN[n - 1][k]) % modo
	return NparN
liNK = list(([int(input().strip()), int(input().strip())] for _ in range(int(input().strip()))))
tr = rList(max((n for (n, _) in liNK)), max((k for (_, k) in liNK)))
for (N, K) in liNK:
	print(tr[N][K])


d = {}
d[0] = [1]
d[1] = [1, 1]
for i in range(2, 2000):
	d[i - 1] = [1]
	for j in range(1, i - 1):
		d[i - 1] += [d[i - 2][j - 1] + d[i - 2][j]]
	d[i - 1] += [1]

def ncr(n, r):
	return d[n][r]
for _ in range(int(input())):
	n = int(input())
	k = int(input())
	res = ncr(n + k - 1, k)
	if len(str(res)) > 9:
		print(int(str(res)[-9:]))
	else:
		print(res)


import sys

class NCRTable(object):

	def __init__(self, depth=2500, mod=10 ** 9):
		self.depth = depth
		self.table = []
		self.mod = mod
		self.generate()

	def generate(self):
		self.table.append([])
		self.table.append([1, 1])
		for i in range(2, self.depth):
			self.table.append([1] + [(self.table[i - 1][x - 1] + self.table[i - 1][x]) % self.mod for x in range(1, len(self.table[i - 1]))] + [1])

	def choose(self, n, r):
		return self.table[n][r]

	def row(self, n):
		return self.table[n]
t = int(input())
table = NCRTable()
for _ in range(t):
	n = int(input())
	k = int(input())
	print(table.choose(k + n - 1, n - 1))