Gaurang has grown up in a mystical universe. He is faced by $n$ consecutive 2D planes. He shoots a particle of decay age $k$ at the planes.

A particle can pass through a plane directly, however, every plane produces an identical copy of the particle going in the opposite direction with a decay age $k-1$. If a particle has decay age equal to $1$, it will NOT produce a copy.

For example, if there are two planes and a particle is shot with decay age $3$ (towards the right), the process is as follows: (here, $D(x)$ refers to a single particle with decay age $x$)

the first plane produces a $D(2)$ to the left and lets $D(3)$ continue on to the right;

the second plane produces a $D(2)$ to the left and lets $D(3)$ continue on to the right;

the first plane lets $D(2)$ continue on to the left and produces a $D(1)$ to the right;

the second plane lets $D(1)$ continue on to the right ($D(1)$ cannot produce any copies).

In total, the final multiset $S$ of particles is $\{D(3), D(2), D(2), D(1)\}$. (See notes for visual explanation of this test case.)

Gaurang is unable to cope up with the complexity of this situation when the number of planes is too large. Help Gaurang find the size of the multiset $S$, given $n$ and $k$.

Since the size of the multiset can be very large, you have to output it modulo $10^9+7$.

Note: Particles can go back and forth between the planes without colliding with each other.


-----Input-----

The first line of the input contains the number of test cases $t$ ($1 \le t \le 100$). Then, $t$ lines follow, each containing two integers $n$ and $k$ ($1 \le n, k \le 1000$).

Additionally, the sum of $n$ over all test cases will not exceed $1000$, and the sum of $k$ over all test cases will not exceed $1000$. All test cases in one test are different.


-----Output-----

Output $t$ integers. The $i$-th of them should be equal to the answer to the $i$-th test case.


-----Examples-----

Input
4
2 3
2 2
3 1
1 3
Output
4
3
1
2
Input
3
1 1
1 500
500 250
Output
1
2
257950823


-----Note-----

Let us explain the first example with four test cases.

Test case 1: ($n = 2$, $k = 3$) is already explained in the problem statement.

See the below figure of this simulation. Each straight line with a different color represents the path of a different particle. As you can see, there are four distinct particles in the multiset. Note that the vertical spacing between reflected particles is for visual clarity only (as mentioned before, no two distinct particles collide with each other)

Test case 2: ($n = 2$, $k = 2$) is explained as follows:

the first plane produces a $D(1)$ to the left and lets $D(2)$ continue on to the right;

the second plane produces a $D(1)$ to the left and lets $D(2)$ continue on to the right;

the first plane lets $D(1)$ continue on to the left ($D(1)$ cannot produce any copies).

Total size of multiset obtained $\{D(1), D(1), D(2)\}$ is equal to three.

Test case 3: ($n = 3$, $k = 1$), there are three planes, but decay age is only one. So no new copies are produced while the one particle passes through the planes. Hence, the answer is one.

Test case 4: ($n = 1$, $k = 3$) there is only one plane. The particle produces a new copy to the left. The multiset $\{D(2), D(3)\}$ is of size two.

Difficulty: MEDIUM_HARD
Tags: Dynamic programming

Data structures

Complete search
Skill types: Dynamic programming

Data structures

Complete search

Starter code:

Solutions:
import sys
import collections
import math
import bisect
import heapq
inf = sys.maxsize

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

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

def input():
	return sys.stdin.readline().strip()
mod = 1000000007
for _ in range(int(input())):
	(n, k) = get_ints()
	dp = [[0 for i in range(1005)] for j in range(1005)]
	for i in range(1, k + 1):
		for j in range(n + 1):
			if i == 1:
				dp[i][j] = 1
			elif j == 0:
				dp[i][j] = 1
			else:
				dp[i][j] = (dp[i][j - 1] % mod + dp[i - 1][n - j] % mod) % mod
	print(dp[k][n] % mod)


T = int(input())
M = 10 ** 9 + 7
while T:
	(n, k) = map(int, input().split())
	X = [1] * (n - 1)
	z = 1 + min(k - 1, 1) * n
	for i in range(k - 2):
		for j in range(1, n - 1):
			X[j] = (X[j] + X[j - 1]) % M
		z = (z + sum(X)) % M
		X = X[::-1]
	print(z % M)
	T = T - 1


import os
import sys
from io import BytesIO, IOBase
import heapq as h
import bisect
import math as mt
from types import GeneratorType
BUFSIZE = 8192

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

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')
import sys
from math import ceil, log2
INT_MAX = sys.maxsize
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections as col
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 minVal(x, y):
	return x if x < y else y

def getMid(s, e):
	return s + (e - s) // 2

def RMQUtil(st, ss, se, qs, qe, index):
	if qs <= ss and qe >= se:
		return st[index]
	if se < qs or ss > qe:
		return INT_MAX
	mid = getMid(ss, se)
	return minVal(RMQUtil(st, ss, mid, qs, qe, 2 * index + 1), RMQUtil(st, mid + 1, se, qs, qe, 2 * index + 2))

def RMQ(st, n, qs, qe):
	if qs < 0 or qe > n - 1 or qs > qe:
		print('Invalid Input')
		return -1
	return RMQUtil(st, 0, n - 1, qs, qe, 0)

def constructSTUtil(arr, ss, se, st, si):
	if ss == se:
		st[si] = arr[ss]
		return arr[ss]
	mid = getMid(ss, se)
	st[si] = minVal(constructSTUtil(arr, ss, mid, st, si * 2 + 1), constructSTUtil(arr, mid + 1, se, st, si * 2 + 2))
	return st[si]

def constructST(arr, n):
	x = int(ceil(log2(n)))
	max_size = 2 * int(2 ** x) - 1
	st = [0] * max_size
	constructSTUtil(arr, 0, n - 1, st, 0)
	return st
MOD = 10 ** 9 + 7
mod = 10 ** 9 + 7
p = 10 ** 9 + 7

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def z_array(s1):
	n = len(s1)
	z = [0] * n
	(l, r, k) = (0, 0, 0)
	for i in range(1, n):
		if i > r:
			(l, r) = (i, i)
			while r < n and s1[r - l] == s1[r]:
				r += 1
			z[i] = r - l
			r -= 1
		else:
			k = i - l
			if z[k] < r - i + 1:
				z[i] = z[k]
			else:
				l = i
				while r < n and s1[r - l] == s1[r]:
					r += 1
				z[i] = r - l
				r -= 1
	return z

def fs(x):
	if x < 2:
		return 0
	return x * (x - 1) // 2
t = int(input())

def solve():
	if k == 1:
		return 1
	mod = 10 ** 9 + 7
	suma = n + 1
	l = [1] * n
	cnt = 1
	for j in range(k - 2, 0, -1):
		sum1 = 0
		for i in range(n):
			sum1 += l[i]
			sum1 %= mod
		if cnt == 0:
			cnt = 1
			sum2 = 0
			for i in range(n):
				sum2 += l[i]
				sum2 %= mod
				l[i] = sum1 - sum2
				suma = (suma + l[i]) % mod
		else:
			cnt = 0
			sum2 = 0
			for i in range(n - 1, -1, -1):
				sum2 += l[i]
				sum2 %= mod
				l[i] = sum1 - sum2
				suma = (suma + l[i]) % mod
	return suma % mod
for _ in range(t):
	(n, k) = map(int, input().split())
	print(solve())


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	dp = []
	for i in range(0, 1005):
		dp.append([0] * 1005)
	ans = 1
	for i in range(1, k + 1):
		for j in range(0, n + 1):
			if j == 0 or i == 1:
				dp[i][j] = 1
			else:
				dp[i][j] = (dp[i - 1][n - j] + dp[i][j - 1]) % 1000000007
	print(dp[k][n])


MODULE = 10 ** 9 + 7

def r(n, k):
	a = [1 for _ in range(n + 1)]
	new_a = [0 for _ in range(n + 1)]
	cur_k = 1
	while cur_k < k:
		new_a[0] = 1
		for i in range(1, n + 1):
			new_a[i] = (new_a[i - 1] + a[n - i]) % MODULE
		cur_k += 1
		(a, new_a) = (new_a, a)
	return a[-1]

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		print(r(n, k))
main()


from sys import stdin
modulus = int(10 ** 9 + 7)

def resultat(max_decay_age, width):
	if max_decay_age == 1:
		return 1
	current_layer = [1] * (width - 1)
	for thing in range(max_decay_age - 2):
		current_layer = list(reversed(current_layer))
		new_layer = [0] * (width - 1)
		total = 1
		for i in range(width - 1):
			total = (total + current_layer[i]) % modulus
			new_layer[i] = total
		current_layer = new_layer
	return (sum(current_layer) + 2) % modulus
count = int(stdin.readline())
for _ in range(count):
	(width, max_decay_age) = (int(x) for x in stdin.readline().split())
	print(resultat(max_decay_age, width))


MOD = 1000000000.0 + 7
T = int(input())
coldp = []

def getsum(row1, row2, col):
	global coldp
	row1 -= 1
	if row1 < 0:
		return coldp[row2][col]
	else:
		return coldp[row2][col] - coldp[row1][col]
for t in range(T):
	(n, k) = [int(i) for i in input().split()]
	dp = [[-1 for i in range(k + 1)] for j in range(n + 1)]
	coldp = [[0 for i in range(k + 1)] for j in range(n + 1)]
	dp[0][0] = 0
	colsum = 0
	newcolsum = 0
	coldp[0][0] = 0
	mem = dict()
	for col in range(k + 1):
		for row in range(n + 1):
			if col == 0:
				dp[row][col] = 0
				coldp[row][col] = 0
			elif row == 0:
				dp[row][col] = 1
				coldp[row][col] = 1
			elif col == 1:
				dp[row][col] = 1
				coldp[row][col] = (dp[row][col] + coldp[row - 1][col]) % MOD
			else:
				ans = 0
				if col < 3:
					for val in range(n - 1, n - row - 1, -1):
						ans += dp[val][col - 1]
				else:
					if n - row - 1 < 0:
						rem = 0
					else:
						rem = coldp[n - row - 1][col - 1]
					ans = coldp[n - 1][col - 1] - rem
				dp[row][col] = (1 + ans) % MOD
				coldp[row][col] = (coldp[row - 1][col] + dp[row][col]) % MOD
	print(int(dp[n][k]))


def fog():
	s = list(map(int, input().split()))
	n = s[0]
	k = s[1]
	lst = []
	sm = 0
	for i in range(n - 1):
		lst.append(1)
	if k == 1:
		print(1)
	elif n == 1:
		print(2)
	elif k == 2:
		print(n + 1)
	elif n == 2:
		print(k + 1)
	else:
		for i in range(k - 2):
			lst1 = [sum(lst)]
			for i in range(n - 2):
				lst1.append((lst1[i] - lst[-i - 1]) % (10 ** 9 + 7))
			sm += sum(lst1) % (10 ** 9 + 7)
			sm = sm % (10 ** 9 + 7)
			lst = lst1
		print(sm + 1 + n)
t = int(input())
while t > 0:
	t -= 1
	fog()


T = int(input())
while T:
	(n, k) = map(int, input().split())
	ps = [[0] * 1007 for i in range(1007)]
	ans = 1
	if k > 1:
		ans += n
		for i in range(1, n + 1):
			ps[k - 1][i] = 1
	turn = 0
	for i in range(k - 2, 0, -1):
		if not turn:
			for j in range(n - 1, 0, -1):
				ps[i][j] = ps[i][j + 1] + ps[i + 1][j + 1]
				ps[i][j] %= 1000000007
				ans += ps[i][j]
				ans %= 1000000007
		else:
			for j in range(2, n + 1):
				ps[i][j] = ps[i][j - 1] + ps[i + 1][j - 1]
				ps[i][j] %= 1000000007
				ans += ps[i][j]
				ans %= 1000000007
		turn = 1 - turn
	T -= 1
	print(ans)


import sys
mod = int(1000000000.0 + 7)
input = sys.stdin.readline

def iter_solver(N, K):
	dp = [[[-1 for _ in range(2)] for __ in range(K + 1)] for ___ in range(N + 1)]
	for i in range(1, N + 1):
		dp[i][1][0] = dp[i][1][1] = 1
	for k in range(2, K + 1):
		for n in range(N, 0, -1):
			ans = 2
			if n < N:
				ans += dp[n + 1][k][0] - 1
				ans %= mod
			if n > 1:
				ans += dp[n - 1][k - 1][1] - 1
				ans %= mod
			dp[n][k][0] = ans
		for n in range(1, N + 1):
			ans = 2
			if n < N:
				ans += dp[n + 1][k - 1][0] - 1
				ans %= mod
			if n > 1:
				ans += dp[n - 1][k][1] - 1
				ans %= mod
			dp[n][k][1] = ans
	return dp[1][K][0]

def solve(curr, k, dir):
	global dp
	if k == 1:
		return 1
	if dp[curr][k][dir] != -1:
		return dp[curr][k][dir]
	ans = 2
	if dir == 1:
		if curr < n:
			ans += solve(curr + 1, k, dir) - 1
			ans %= mod
		if curr > 1:
			ans += solve(curr - 1, k - 1, 1 - dir) - 1
			ans %= mod
	else:
		if curr > 1:
			ans += solve(curr - 1, k, dir) - 1
			ans %= mod
		if curr < n:
			ans += solve(curr + 1, k - 1, 1 - dir) - 1
			ans %= mod
	dp[curr][k][dir] = ans
	return ans
t = int(input())
while t > 0:
	t -= 1
	(n, k) = list(map(int, input().split()))
	print(iter_solver(n, k))


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 time import time
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')
lcm = lambda x, y: x * y // gcd(x, y)
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	(n, k) = R()
	if k == 1:
		print(1)
		continue
	d = [1] * n
	d[0] = 0
	p = n - 1
	s = p
	for i in range(k - 2):
		q = 0
		z = d.copy()
		for j in range(n - 1, 0, -1):
			p = (p - z[n - j - 1]) % N
			d[j] = p
			q = (q + d[j]) % N
		p = q
		s = (s + p) % N
	print((s + 2) % N)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	sum = []
	if k == 1:
		print(1)
	elif n == 1:
		print(2)
	elif k == 2:
		print(n + 1)
	else:
		for i in range(k):
			tmp = [0] * (n + 1)
			sum.append(tmp)
		for i in range(n + 1):
			sum[0][i] = 1
		for i in range(1, k):
			for j in range(n + 1):
				if j == 0:
					sum[i][j] = 1
				else:
					sum[i][j] = (sum[i][j - 1] + sum[i - 1][n - j]) % (10 ** 9 + 7)
		print(sum[-1][-1])


from itertools import accumulate
t = int(input())
mod = 10 ** 9 + 7
for _ in range(t):
	(n, k) = map(int, input().split())
	now = [0] * (n + 1)
	now[0] = 1
	now[1] = 1
	ans = 0
	for i in range(k):
		if i & 1:
			for j in reversed(range(n - 1)):
				now[j] += now[j + 1]
				now[j] %= mod
			ans += now[0]
			ans %= mod
			now[0] = 0
		else:
			for j in range(1, n):
				now[j + 1] += now[j]
				now[j] %= mod
			ans += now[-1]
			ans %= mod
			now[-1] = 0
	print(ans)


MOD = 10 ** 9 + 7
t = int(input())
for test in range(t):
	(n, k) = [int(i) for i in input().split()]
	if k == 1:
		print(1)
	elif k == 2:
		print(n + 1)
	elif n == 1:
		print(2)
	else:
		ans = n + 1
		v = [1 for i in range(n - 1)]
		for my_iter in range(k - 2):
			v_new = [0 for i in range(n - 1)]
			v_new[-1] = v[0]
			for it in range(1, n - 1):
				v_new[-it - 1] = (v_new[-it] + v[it]) % MOD
			ans += sum(v_new) % MOD
			v = v_new
		print(ans % MOD)


(I, R) = (input, range)
for _ in R(int(I())):
	(n, k) = map(int, I().split())
	D = [[1] * (n + 1)] + [[1] + [0] * n for _ in R(k)]
	for d in R(1, k):
		for i in R(n):
			D[d][i + 1] = (D[d][i] + D[d - 1][n - i - 1]) % (10 ** 9 + 7)
	print(D[k - 1][n])


import sys
get_string = lambda : sys.stdin.readline().strip()
get_intmap = lambda : map(int, get_string().split())
for t in range(int(get_string())):
	(n, k) = get_intmap()
	m = int(1000000000.0 + 7)
	current_decay_age = k
	total_particles = 1
	right = 1
	start = 1
	if current_decay_age > 1:
		l = [1] * n
		total_particles += n
		current_decay_age -= 1
	while current_decay_age > 1:
		tmp_arr = [0] * n
		tmp = 0
		for ind in range(n - 1):
			tmp += l[ind + 1] % m
			tmp_arr[ind] = tmp
		total_particles = (total_particles + sum(tmp_arr)) % m
		l = tmp_arr[::-1]
		current_decay_age -= 1
	print(total_particles)


import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string

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
		self.BUFSIZE = 8192

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.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, self.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')

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

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

def get_int_grid(n):
	return [get_ints() for _ in range(n)]

def get_str():
	return input().strip()

def get_strs():
	return get_str().split(' ')

def flat_list(arr):
	return [item for subarr in arr for item in subarr]

def yes_no(b):
	if b:
		return 'YES'
	else:
		return 'NO'

def binary_search(good, left, right, delta=1, right_true=False):
	limits = [left, right]
	while limits[1] - limits[0] > delta:
		if delta == 1:
			mid = sum(limits) // 2
		else:
			mid = sum(limits) / 2
		if good(mid):
			limits[int(right_true)] = mid
		else:
			limits[int(~right_true)] = mid
	if good(limits[int(right_true)]):
		return limits[int(right_true)]
	else:
		return False

def prefix_sums(a):
	p = [0]
	for x in a:
		p.append(p[-1] + x)
	return p

def solve_a():
	n = get_int()

	def good(m):
		s = 0
		for c in str(m):
			s += int(c)
		return math.gcd(s, m) > 1
	if good(n):
		return n
	elif good(n + 1):
		return n + 1
	else:
		return n + 2

def solve_b():
	(n, W) = get_ints()
	w = get_ints()
	w.sort()
	used = [0] * (n + 1)
	level = 0
	prev = w[-1]
	while w:
		curr = w.pop()
		if curr < prev:
			level = 0
		capacity = W - used[level]
		while curr > capacity:
			level += 1
			capacity = W - used[level]
		used[level] += curr
		prev = curr
	return len([level for level in used if level > 0])

def solve_c():
	(n, k) = get_ints()
	M = 10 ** 9 + 7
	ans = 0
	counts = [0] * (n + 1)
	counts[n] = 1
	for _ in range(k):
		new_counts = [0] * (n + 1)
		for i in range(n + 1):
			ans = (ans + counts[i]) % M
			if i > 0:
				new_counts[n - i] += counts[i]
				new_counts[n - i] %= M
		for i in range(n):
			new_counts[i] += new_counts[i - 1]
			new_counts[i] %= M
		counts = new_counts.copy()
	return ans % M
t = get_int()
for _ in range(t):
	print(solve_c())


import sys
import math
import random
input = sys.stdin.readline
t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	if n == 1:
		if k == 1:
			print(1)
		else:
			print(2)
		t -= 1
		continue
	if k == 1:
		print(1)
		t -= 1
		continue
	a = 2
	l = [1] * n
	d = 1
	for i in range(k - 1):
		if d == 1:
			ps = l[n - 1]
			l[n - 1] = 0
			for j in range(n - 2, -1, -1):
				(l[j], ps) = ((l[j + 1] + ps) % 1000000007, l[j])
			a += l[0] % 1000000007
			d = 0
		else:
			ps = l[0]
			l[0] = 0
			for j in range(1, n):
				(l[j], ps) = ((l[j - 1] + ps) % 1000000007, l[j])
			a += l[n - 1] % 1000000007
			d = 1
	print(a % 1000000007)
	t -= 1


from math import *
import sys
input = sys.stdin.readline

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

def st():
	return input().rstrip('\n')

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

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	(n, k) = ma()
	dp = [[0 for i in range(k + 1)] for j in range(n + 1)]
	for i in range(k + 1):
		dp[0][i] = 1
	for i in range(n + 1):
		dp[i][1] = 1
	p = 10 ** 9 + 7
	for i in range(2, k + 1):
		for j in range(1, n + 1):
			dp[j][i] = (dp[j - 1][i] + dp[n - j][i - 1]) % p
	print(dp[-1][-1])


import os
import sys
from bisect import bisect_right
from collections import Counter, deque, defaultdict
from io import BytesIO, IOBase
from math import gcd, inf, sqrt, ceil, radians, cos, sin

def lcm(a, b):
	return a * b // gcd(a, b)

def sieve():
	global spf, adj, MAXN
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(2, MAXN):
		if i * i > MAXN:
			break
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def getdistinctFactorization(n):
	global adj, spf, MAXN
	for i in range(1, n + 1):
		index = 1
		x = i
		if x != 1:
			adj[i].append(spf[x])
		x = x // spf[x]
		while x != 1:
			if adj[i][index - 1] != spf[x]:
				adj[i].append(spf[x])
				index += 1
			x = x // spf[x]

def printDivisors(n):
	i = 2
	z = [1, n]
	while i <= sqrt(n):
		if n % i == 0:
			if n / i == i:
				z.append(i)
			else:
				z.append(i)
				z.append(n // i)
		i = i + 1
	return z

def create(n, x, f):
	pq = len(bin(n)[2:])
	if f == 0:
		tt = min
	else:
		tt = max
	dp = [[inf] * n for _ in range(pq)]
	dp[0] = x
	for i in range(1, pq):
		for j in range(n - (1 << i) + 1):
			dp[i][j] = tt(dp[i - 1][j], dp[i - 1][j + (1 << i - 1)])
	return dp

def enquiry(l, r, dp, f):
	if l > r:
		return inf if not f else -inf
	if f == 1:
		tt = max
	else:
		tt = min
	pq1 = len(bin(r - l + 1)[2:]) - 1
	return tt(dp[pq1][l], dp[pq1][r - (1 << pq1) + 1])

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
	x = []
	for i in range(2, n + 1):
		if prime[i]:
			x.append(i)
	return x

def dfs(i, vis, adj):
	c = []
	st = []
	st.append(i)
	while st:
		xx = st.pop()
		if not vis[xx]:
			vis[xx] = 1
			c.append(xx)
			for i in adj[xx]:
				st.append(i)
	return (vis, c)

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		mod = 10 ** 9 + 7
		y = [1] * n
		x = [0] * n
		s = 0
		p = 1
		for i in range(k - 1):
			if p:
				for j in range(len(y)):
					s = (s + y[j]) % mod
				an = y[n - 1] % mod
				for j in range(n - 2, -1, -1):
					x[j] = an
					an = (an + y[j]) % mod
				y = [0] * n
				p ^= 1
			else:
				for j in range(len(x)):
					s = (s + x[j]) % mod
				an = x[0] % mod
				for j in range(1, n):
					y[j] = an
					an = (an + x[j]) % mod
				x = [0] * n
				p ^= 1
		print(s + 1)
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 sys
input = lambda : sys.stdin.readline().rstrip()
MOD = 1000000000.0 + 7

class Problem:

	def __init__(self):
		pass

	def solve(self):
		ans = 0
		(N, K) = map(int, input().split())
		dp = [[0 for j in range(N + 1)] for i in range(K + 1)]
		for i in range(1, K + 1):
			for j in range(N + 1):
				if i == 1 or j == 0:
					dp[i][j] = 1
					continue
				dp[i][j] = int((dp[i][j - 1] + dp[i - 1][N - j]) % MOD)
		ans = dp[K][N]
		print(ans)

def main():
	p = Problem()
	T = int(input())
	while T:
		p.solve()
		T -= 1
main()


t = int(input())
inf = 10 ** 9 + 7
for i in range(t):
	(n, k) = map(int, input().split())
	a = [0] * (n + 1)
	a[1] = 1
	ans = 1
	if k > 1:
		ans += 1
	for i in range(k - 1):
		pref = [0] * (n + 1)
		if i % 2 == 0:
			for j in range(1, n):
				pref[j] = (a[j] + pref[j - 1]) % inf
				ans = (ans + pref[j]) % inf
		else:
			for j in range(n - 1, 0, -1):
				pref[j] = (a[j] + pref[j + 1]) % inf
				ans = (ans + pref[j]) % inf
		a = pref
	print(ans)


t = int(input())
mod = 10 ** 9 + 7
for _ in range(t):
	(n, k) = map(int, input().split())
	ans = 2
	if k == 1:
		ans = 1
	elif n == 1:
		ans = 2
	elif k > 1:
		count = 0
		temp = [1 for i in range(n - 1)]
		for i in range(k - 1, 0, -1):
			if count == 0:
				ans += sum(temp)
				ans %= mod
				for j in range(1, n - 1):
					temp[j] = temp[j - 1] + temp[j]
					temp[j] %= mod
				count = 1
			elif count == 1:
				ans += sum(temp)
				ans %= mod
				for j in range(n - 3, -1, -1):
					temp[j] = temp[j + 1] + temp[j]
					temp[j] %= mod
				count = 0
	print(ans)


mod = 1000000007
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = [[0] * (n + 1) for x in range(k)]
	for _ in range(n + 1):
		a[0][_] = 1
	for _ in range(1, k):
		cur = 0
		for __ in range(n + 1):
			a[_][__] = cur + 1
			if __ < n:
				cur = (cur + a[_ - 1][n - 1 - __]) % mod
	print(a[k - 1][n])


import os, 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))
try:
	(sys.stdin, sys.stdout) = (open('in.txt', 'r'), open('out.txt', 'w'))
except:
	pass
ii1 = lambda : int(sys.stdin.readline().strip())
is1 = lambda : sys.stdin.readline().strip()
iia = lambda : list(map(int, sys.stdin.readline().strip().split()))
isa = lambda : sys.stdin.readline().strip().split()
mod = int(1000000000.0 + 7)
from collections import *
from math import *
from collections import deque as dq

def solve(N, K):
	dp = [[[-1 for k in range(2)] for j in range(K + 1)] for i in range(N + 1)]
	for i in range(1, N + 1):
		dp[i][1][0] = 1
		dp[i][1][1] = 1
	for k in range(2, K + 1):
		for n in range(N, 0, -1):
			ans = 2
			if n < N:
				ans += dp[n + 1][k][0] - 1
				ans %= mod
			if n > 1:
				ans += dp[n - 1][k - 1][1] - 1
				ans %= mod
			dp[n][k][0] = ans
		for n in range(1, N + 1):
			ans = 2
			if n < N:
				ans += dp[n + 1][k - 1][0] - 1
				ans %= mod
			if n > 1:
				ans += dp[n - 1][k][1] - 1
				ans %= mod
			dp[n][k][1] = ans
	print(dp[1][K][0])
for _ in range(ii1()):
	(n, k) = iia()
	solve(n, k)


import sys

def load_sys():
	return sys.stdin.readlines()

def load_local():
	with open('input.txt', 'r') as f:
		input = f.readlines()
	return input

def f(n, k):
	MOD_NUM = 10 ** 9 + 7
	dp = [[0 for _ in range(n + 2)] for _ in range(k + 1)]
	for age in range(1, k + 1):
		dp[age][0] = 1
	for age in range(k + 1):
		for idx in range(1, n + 1):
			dp[age][idx] = (dp[age][idx - 1] + dp[age - 1][n - idx]) % MOD_NUM
	return dp[k][n]
input = load_sys()
for i in range(1, len(input)):
	arr = input[i].split()
	(n, k) = (int(arr[0]), int(arr[1]))
	print(f(n, k))


mod = 10 ** 9 + 7
cas = int(input())
while cas:
	cas -= 1
	(n, k) = map(int, input().split())
	dp = [1 for i in range(n)]
	ans = 1
	for i in range(k - 1):
		tmp = 0
		for j in range(n):
			ans = (ans + dp[j]) % mod
		if i % 2 == 0:
			for j in range(n - 1, -1, -1):
				tt = dp[j]
				dp[j] = tmp
				tmp = (tmp + tt) % mod
		else:
			for j in range(n):
				tt = dp[j]
				dp[j] = tmp
				tmp = (tmp + tt) % mod
	print(ans)


modulo = 10 ** 9 + 7
for ct in range(int(input())):
	(n, k) = map(int, input().split())
	dp = [[0 for j in range(n + 1)] for i in range(k + 1)]
	for i in range(k + 1):
		for j in range(n + 1):
			if i == 1 or j == 0:
				dp[i][j] = 1
			else:
				dp[i][j] = (dp[i][j - 1] + dp[i - 1][n - j]) % modulo
	print(dp[-1][-1])


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
MOD = 10 ** 9 + 7
for _ in range(t):
	(n, k) = map(int, input().split())
	dp = []
	for i in range(k + 1):
		dp.append([0] * (n + 1))
	for i in range(n + 1):
		dp[1][i] = 1
	for i in range(1, k + 1):
		dp[i][0] = 1
		for j in range(1, n + 1):
			dp[i][j] = (dp[i][j - 1] + dp[i - 1][n - j]) % MOD
	print(dp[k][n])


import math
from heapq import heappush, heappop, heapify
import random
import string
from collections import deque
from bisect import bisect, bisect_left, bisect_right, insort
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 = 1000000000 + 7
mod2 = 998244353
for _ in range(I()):
	(n, k) = M()
	dp = [[0 for i in range(k + 1)] for j in range(n + 1)]
	for i in range(1, k + 1):
		dp[0][i] = 1
	for i in range(1, k + 1):
		for j in range(1, n + 1):
			dp[j][i] = (dp[n - j][i - 1] + dp[j - 1][i]) % mod1
	print(dp[-1][-1])


from __future__ import division, print_function
import math
import sys
import os
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

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

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
mx = 10 ** 9 + 7
dp = [[0 for i in range(1005)] for j in range(1005)]
for i in range(1005):
	dp[1][i] = 1
for i in range(1005):
	dp[i][0] = 1
for _ in range(inp()):
	(n, k) = invr()
	for i in range(2, k + 2):
		for j in range(1, n + 2):
			dp[i][j] = (dp[i - 1][n - j] + dp[i][j - 1]) % mx
	print(dp[k][n])


e = 1000000007
ma = {}

def get(n, k, f):
	if ma[n][k][f] == -1:
		if k == 1:
			ma[n][k][f] = 1
		elif k == 2:
			ma[n][k][f] = f + 1
		elif f == 0:
			ma[n][k][f] = 1
		else:
			res = get(n, k - 1, n - f) + get(n, k, f - 1)
			if res > e:
				res %= e
			ma[n][k][f] = max(0, res)
	return ma[n][k][f]
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n not in ma:
		ma[n] = [[-1] * (n + 1) for i in range(k + 1)]
	else:
		if len(ma[n][0]) <= n:
			prevn = ma[n][0]
			for i in range(len(ma[n])):
				for j in range(n - prevn):
					ma[n][i].append(-1)
		if len(ma[n]) <= k:
			ma[n] += [[-1] * (n + 1) for i in range(k - len(ma[n]) + 1)]
	ans = get(n, k, n)
	print(ans)


import os
import sys
from io import BytesIO, IOBase

def main():
	pass
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')
from importlib import import_module

def _heappop_max(heap):
	lastelt = heap.pop()
	if heap:
		returnitem = heap[0]
		heap[0] = lastelt
		_siftup_max(heap, 0)
		return returnitem
	return lastelt

def _heappush_max(heap, item):
	heap.append(item)
	_siftdown_max(heap, 0, len(heap) - 1)

def _heappushpop_max(heap, item):
	if heap and heap[0] > item:
		(item, heap[0]) = (heap[0], item)
		_siftup_max(heap, 0)
	return item

def _heapreplace_max(heap, item):
	returnitem = heap[0]
	heap[0] = item
	_siftup_max(heap, 0)
	return returnitem
_heapops = ['heapify', 'heappush', 'heappop', 'heappushpop', 'heapreplace', '_siftup', '_siftdown_heapify_max', '_heappush_max', '_heappop_max', '_heappushpop_max', '_heapreplace_max', '_siftup_max', '_siftdown_max']
for module in ['heapq', '_heapq']:
	try:
		m = import_module(module)
		for f in _heapops:
			try:
				globals().update({f: getattr(m, f)})
			except:
				pass
	except:
		pass

class Heap(object):

	def __init__(self, iterable=None, reverse=False):
		if reverse:
			(self.heapify, self.heappush, self.heappop) = (_heapify_max, _heappush_max, _heappop_max)
			(self.heappushpop, self.heapreplace) = (_heappushpop_max, _heapreplace_max)
		else:
			(self.heapify, self.heappush, self.heappop) = (heapify, heappush, heappop)
			(self.heappushpop, self.heapreplace) = (heappushpop, heapreplace)
		if iterable is None:
			iterable = []
		self.heap = list(iterable)
		self.heapify(self.heap)

	def peek(self):
		return self.heap[0]

	def push(self, item):
		self.heappush(self.heap, item)

	def pop(self):
		return self.heappop(self.heap)

	def poppush(self, item):
		return self.heapreplace(self.heap, item)
	replace = poppush

	def pushpop(self, item):
		return self.heappushpop(self.heap, item)

	def __len__(self):
		return len(self.heap)

	def __iter__(self):
		return iter(self.heap)

	def __contains__(self, item):
		return item in iter(self)

	def __repr__(self):
		return 'Heap({content})'.format(content=heap)

class OrderHeap(Heap):

	def __init__(self, iterable=None, key=lambda x: x, reverse=False):
		if iterable is None:
			iterable = []
		self.key = key
		super(OrderHeap, self).__init__(((key(item), item) for item in iterable), reverse=reverse)

	def peek(self):
		return self.heap[0][1]

	def push(self, item):
		self.heappush(self.heap, (self.key(item), item))

	def pop(self):
		return self.heappop(self.heap)[1]

	def poppush(self, item):
		return self.heapreplace(self.heap, (self.key(item), item))[1]
	replace = poppush

	def pushpop(self, item):
		return self.heappushpop(self.heap, (self.key(item), item))[1]

	def __iter__(self):
		return (item_tuple[1] for item_tuple in super(OrderHeap, self).__iter__())

	def __repr__(self):
		return 'OrderHeap({content}, key={key})'.format(content=self.heap, key=self.key)

class RemovalHeap(Heap):

	def __init__(self, iterable=None, reverse=False):
		if iterable is None:
			iterable = []
		_list = list(iterable)
		self._item_set = set(_list)
		if len(_list) != len(self._item_set):
			raise RuntimeError('duplicate items not allowed: {_list}'.format(_list=_list))
		super(RemovalHeap, self).__init__(_list, reverse=reverse)

	def peek(self):
		return_item = self.heap[0]
		while return_item not in self._item_set:
			self.heappop(self.heap)
			return_item = self.heap[0]
		return return_item

	def push(self, item):
		if item in self._item_set:
			raise RuntimeError('duplicate item not allowed: {item}'.format(item=item))
		self.heappush(self.heap, item)
		self._item_set.add(item)

	def pop(self):
		return_item = self.heappop(self.heap)
		while return_item not in self._item_set:
			return_item = self.heappop(self.heap)
		self._item_set.remove(return_item)
		self.sweep()
		return return_item

	def remove(self, item):
		self._item_set.remove(item)
		self.sweep()

	def poppush(self, item):
		if item in self._item_set:
			raise RuntimeError('duplicate item not allowed: {item}'.format(item=item))
		self._item_set.add(item)
		while self.heap[0] not in self._item_set:
			self.heappop(self.heap)
		return_item = self.heapreplace(self.heap, item)
		self._item_set.remove(return_item)
		return return_item
	replace = poppush

	def pushpop(self, item):
		if item in self._item_set:
			raise RuntimeError('duplicate item not allowed: {item}'.format(item=item))
		self._item_set.add(item)
		return_item = self.heappushpop(self.heap, item)
		while return_item not in self._item_set:
			return_item = self.heappop(self.heap)
		self._item_set.remove(return_item)
		return return_item

	def sweep(self):
		if 2 * len(self._item_set) < super(RemovalHeap, self).__len__():
			self.heap[:] = list(self)
			self.heapify(self.heap)

	def __iter__(self):
		return (item for item in super(RemovalHeap, self).__iter__() if item in self._item_set)

	def __contains__(self, item):
		return item in self._item_set

	def __len__(self):
		return len(self._item_set)

	def __repr__(self):
		return 'RemovalHeap({content})'.format(content=list(self))

class XHeap(Heap):

	def __init__(self, iterable=None, key=lambda x: x, reverse=False):
		if iterable is None:
			iterable = []
		self.key = key
		_list = list(iterable)
		self._item_set = set(_list)
		if len(_list) != len(self._item_set):
			raise RuntimeError('duplicate items not allowed: {_list}'.format(_list=_list))
		super(XHeap, self).__init__(((key(item), item) for item in _list), reverse=reverse)

	def peek(self):
		return_item = self.heap[0][1]
		while return_item not in self._item_set:
			self.heappop(self.heap)
			return_item = self.heap[0][1]
		return return_item

	def push(self, item):
		if item in self._item_set:
			raise RuntimeError('duplicate item not allowed: {item}'.format(item=item))
		self.heappush(self.heap, (self.key(item), item))
		self._item_set.add(item)

	def pop(self):
		return_item = self.heappop(self.heap)[1]
		while return_item not in self._item_set:
			return_item = self.heappop(self.heap)[1]
		self._item_set.remove(return_item)
		self.sweep()
		return return_item

	def remove(self, item):
		self._item_set.remove(item)
		self.sweep()

	def sweep(self):
		if 2 * len(self._item_set) < super(XHeap, self).__len__():
			self.heap[:] = (item_tuple for item_tuple in super(XHeap, self).__iter__() if item_tuple[1] in self._item_set)
			self.heapify(self.heap)

	def poppush(self, item):
		if item in self._item_set:
			raise RuntimeError('duplicate item not allowed: {item}'.format(item=item))
		self._item_set.add(item)
		while self.heap[0][1] not in self._item_set:
			self.heappop(self.heap)
		return_item = self.heapreplace(self.heap, (self.key(item), item))[1]
		self._item_set.remove(return_item)
		return return_item
	replace = poppush

	def pushpop(self, item):
		if item in self._item_set:
			raise RuntimeError('duplicate item not allowed: {item}'.format(item=item))
		self._item_set.add(item)
		return_item = self.heappushpop(self.heap, (self.key(item), item))[1]
		while return_item not in self._item_set:
			return_item = self.heappop(self.heap)[1]
		self._item_set.remove(return_item)
		return return_item

	def __iter__(self):
		return (item_tuple[1] for item_tuple in super(XHeap, self).__iter__() if item_tuple[1] in self._item_set)

	def __contains__(self, item):
		return item in self._item_set

	def __len__(self):
		return len(self._item_set)

	def __repr__(self):
		return 'XHeap({content}, key={key})'.format(content=list(self), key=self.key)
from collections import defaultdict, deque
import heapq, math
for t in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		print(1)
		continue
	if n == 1:
		print(2)
		continue
	res = 1
	arr = [1] * (n - 1)
	res += n
	n -= 1
	k -= 1
	while k != 1:
		temp = arr[-1] % (10 ** 9 + 7)
		for i in range(n - 2, -1, -1):
			arr[i] = (arr[i] + arr[i + 1]) % (10 ** 9 + 7)
			temp += arr[i]
		res = (res + temp) % (10 ** 9 + 7)
		k -= 1
		if k == 1:
			break
		temp = arr[0] % (10 ** 9 + 7)
		for i in range(1, n):
			arr[i] = (arr[i] + arr[i - 1]) % (10 ** 9 + 7)
			temp += arr[i]
		res = (res + temp) % (10 ** 9 + 7)
		k -= 1
	print(res % (10 ** 9 + 7))
main()


MOD = 10 ** 9 + 7
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	dp = [[0] * (n + 1) for _ in range(k)]
	for i in range(n + 1):
		dp[0][i] = 1
	for b in range(1, k):
		cur = 0
		for i in range(n + 1):
			dp[b][i] = cur + 1
			if i < n:
				cur = (cur + dp[b - 1][n - 1 - i]) % MOD
	print(dp[k - 1][n])


import time
from itertools import accumulate
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	M = 10 ** 9 + 7
	if n == 1:
		print(1 + int(k > 1))
	else:
		crossing = [[None for p in range(n)] for age in range(k + 1)]
		crossing[k] = [1 for p in range(n)]
		crossing[k - 1] = list(accumulate(crossing[k]))
		for age in reversed(range(1, k - 1)):
			crossing[age][:-1] = list(accumulate(crossing[age + 1][-2::-1]))
			crossing[age][-1] = crossing[age][-2]
			for p in range(n):
				crossing[age][p] %= M
		print(sum([crossing[age][-1] for age in range(1, k + 1)]) % M)


import collections

def main():
	for _ in range(int(input())):
		(n, k) = tuple(map(int, input().split()))
		dp = [[0] * 1003 for i in range(1003)]
		for i in range(1, k + 1):
			for j in range(n + 1):
				if j == 0 or i == 1:
					dp[i][j] = 1
				else:
					dp[i][j] = int((dp[i - 1][n - j] + dp[i][j - 1]) % (1000000000.0 + 7))
		print(dp[k][n])
main()


t = int(input())
for test in range(1, t + 1):
	(n, k) = list(map(int, input().split()))
	if k == 1:
		print(1)
	elif n == 1:
		print(2)
	else:
		res = 2
		ls = [1 for _ in range(n - 1)]
		for i in range(k - 1):
			new_ls = []
			curr_sum = 0
			for j in range(n - 1):
				res = (res + ls[j]) % (10 ** 9 + 7)
				curr_sum += ls[j] % (10 ** 9 + 7)
				new_ls.append(curr_sum)
			ls = new_ls[::-1]
		print(res)


import collections
import math
t = int(input())
mod = 10 ** 9 + 7
for _ in range(t):
	(n, k) = map(int, input().split())
	d = [0] * n
	dn = d.copy()
	res = 0
	for i in reversed(range(1, k + 1)):
		cur = 1 if i == k else 0
		for j in range(n):
			dn[j] = cur % mod
			cur += d[j]
			cur %= mod
		res += cur
		res %= mod
		d = dn.copy()[::-1]
	print(res)


from copy import deepcopy
MOD = int(10 ** 9 + 7)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		print(1)
		continue
	elif n == 1:
		print(2)
		continue
	ans = n + 1
	dire = -1
	arrows = [1] * (n - 1)
	k -= 1
	while k > 1:
		new_arrows = [0] * (n - 1)
		if dire == -1:
			new_arrows[n - 2] = arrows[n - 2]
			for i in range(n - 3, -1, -1):
				new_arrows[i] = new_arrows[i + 1] + arrows[i]
		else:
			new_arrows[0] = arrows[0]
			for i in range(1, n - 1):
				new_arrows[i] = new_arrows[i - 1] + arrows[i]
		ans += sum(new_arrows)
		ans %= MOD
		dire *= -1
		arrows = [x % MOD for x in new_arrows]
		k -= 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
import math
from collections import Counter
sys.setrecursionlimit(10 ** 9)

def func(n, k, max_val):
	ROWS = max_val
	DP = [[None] * k for i in range(ROWS + 1)]
	for i in range(ROWS + 1):
		DP[i][0] = 1
	for i in range(1, k):
		DP[0][i] = 1
	for j in range(1, k):
		for i in range(1, max_val + 1):
			DP[i][j] = (DP[i - 1][j] + DP[max_val - i][j - 1]) % (10 ** 9 + 7)
	return DP[n][k - 1]

def main():
	num_test = int(parse_input())
	result = []
	for _ in range(num_test):
		(n, k) = [int(i) for i in parse_input().split()]
		result.append(func(n, k, n) % (10 ** 9 + 7))
	print('\n'.join(map(str, result)))
parse_input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
from sys import stdin

def solve(N, K):
	res_array = [0] * K
	if K == 1:
		return 1
	if K == 2:
		return 1 + N
	res_array[0] = 1
	res_array[1] = N
	old_array = [1] * (N - 1)
	for i in range(2, K):
		new_array = [0] * (N - 1)
		val = 0
		for j in range(N - 1):
			val += old_array[j]
			val %= 10 ** 9 + 7
			new_array[N - 1 - j - 1] = val
		old_array = [x for x in new_array]
		res_array[i] = sum(new_array) % (10 ** 9 + 7)
	return sum(res_array) % (10 ** 9 + 7)

def run():
	out = ''
	T = int(input())
	for i in range(T):
		(N, K) = [int(x) for x in stdin.readline().split()]
		print(solve(N, K))
run()


import sys
import math
from bisect import bisect_left
import heapq

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

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

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

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

def FACT(n, mod):
	s = 1
	facts = [1]
	for i in range(1, n + 1):
		s *= i
		s %= mod
		facts.append(s)
	return facts[n]

def C(n, k, mod):
	return FACT(n, mod) * pow(FACT(k, mod) * FACT(n - k, mod) % mod, mod - 2, mod) % mod

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
mod = 10 ** 9 + 7
for _ in range(II()):
	(n, k) = MI()
	if k == 1:
		print(1)
	elif n == 1:
		print(2)
	else:
		ans = n + 1
		a = [1 for i in range(n - 1)]
		for i in range(n - 3, -1, -1):
			a[i] += a[i + 1]
		c = 0
		for i in range(k - 2, 0, -1):
			for j in range(n - 1):
				ans += a[j]
				ans %= mod
			if c == 0:
				for j in range(1, n - 1):
					a[j] += a[j - 1]
					a[j] %= mod
			else:
				for j in range(n - 3, -1, -1):
					a[j] += a[j + 1]
					a[j] %= mod
			c = 1 - c
		print(ans)


def mingrid():
	for _ in range(int(input())):
		n = int(input())
		segcost = input().split()
		minodd = int(segcost[0])
		mineven = int(segcost[1])
		sumodd = minodd
		sumeven = mineven
		codd = 1
		ceven = 1
		res = sumodd + minodd * (n - codd) + sumeven + mineven * (n - ceven)
		for i in range(2, n):
			now = int(segcost[i])
			if (i + 1) % 2:
				minodd = min(minodd, now)
				sumodd += now
				codd += 1
			else:
				mineven = min(mineven, now)
				sumeven += now
				ceven += 1
			res = min(res, sumodd + minodd * (n - codd) + sumeven + mineven * (n - ceven))
		print(res)

def numofpairs():
	n = (10 * 2) ** 7 + 1
	l = [False] * n
	primes = []
	for i in range(2, n):
		if not l[i]:
			for i1 in range(i + i, n, i):
				l[i1] = True
			primes.append(i)
			l[i] = True
	tol = [0, 0]
	for i in range(2, n):
		pos = 0
		t = 0
		while i:
			val = primes[pos]
			if not i:
				tol.append(t)
				break
			elif i < val:
				tol.append(t + 1)
				break
			elif not i % val:
				i //= val
			else:
				pos += 1
				t += 1
	for _ in range(int(input())):
		(c, d, x) = map(int, input().split())
		lim = int(math.sqrt(x)) + 1
		ans = 0
		for i in range(1, lim):
			thing = i + d
			if thing % c:
				continue
			ans += 2 ** tol[thing // c]
		print(ans)

def restoremod():
	for _ in range(int(input())):
		length = int(input()) - 1
		l = input().split()
		t = False
		ife = False
		for i in range(length):
			if int(l[i]) == int(l[i + 1]):
				if i > 0:
					print(-1)
					t = True
					break
				else:
					ife = True
			elif ife:
				print(-1)
				t = True
				break
		if not t:
			posc = 0
			negc = 0
			res = int(l[1]) - int(l[0])
			if res > 0:
				posc = res
			else:
				negc = res
			if not negc:
				for i in range(1, length):
					now = int(l[i]) - int(l[i + 1])
					if now > 0:
						negc = now
						break
			if not posc:
				for i in range(1, length):
					change = int(l[i + 1]) - int(l[i])
					if change > 0:
						posc = change
						break
			if posc and negc:
				mod = posc + negc
			else:
				mod = 0
			c = posc if posc else -negc
			larnum = 0
			for i in range(length):
				nowi = int(l[i])
				larnum = max(larnum, nowi)
				if larnum > mod and mod:
					print(-1)
					t = True
					break
				res = int(l[i + 1]) - nowi
				if res < 0:
					if res != -(mod - c):
						print(-1)
						t = True
						break
				if res > 0:
					if res != c:
						t = True
						print(-1)
						break
			if not t:
				if mod:
					print(mod, c, sep=' ')
				else:
					print(mod)

def restoremod1():
	for _ in range(int(input())):
		num = int(input())
		...

def cells():
	for _ in range(int(input())):
		(row, col, num) = map(int, input().split())
		nr = (num - 1) % row
		nc = (num - 1) // row + 1
		print(nr * col + nc)

def replacement():
	for _ in range(int(input())):
		(l, k) = map(int, input().split())
		s = input()
		(left, righ) = (s.find('*'), s.rfind('*'))
		if righ - left <= k:
			print(2 if righ != left else 1)
		else:
			pos = left
			c = 2
			while righ - pos > k:
				pos = pos + k
				while pos < l and s[pos] != '*':
					pos -= 1
				c += 1
			print(c)
import math
import sys
input = sys.stdin.readline

def string():
	for _ in range(int(input())):
		s = input().rstrip()
		s1 = input().rstrip()
		maxl = 0
		p1 = [0, 0]
		p = [0, 0]
		for i in range(len(s)):
			for i1 in range(i + 1, len(s) + 1):
				pos = s1.find(s[i:i1])
				if pos == -1:
					break
				elif i1 - i <= maxl:
					continue
				elif i1 - i > maxl:
					maxl = i1 - i
					p1 = [pos, pos + maxl]
					p = [i, i + maxl]
		print(p[0] + len(s) - p[1] + (p1[0] + len(s1) - p1[1]) if maxl else len(s) + len(s1))
import collections

def trans(l):
	pos = 0
	while pos < len(l) - 1:
		avg = l[pos] // (len(l) - pos - 1)
		rem = l[pos] % (len(l) - pos - 1)
		l[pos] = 0
		for i in range(pos + 1, len(l)):
			l[i] -= avg
			if l[i] < 0:
				rem += -l[i]
				l[i] = 0
		while pos + 1 < len(l) and l[pos + 1] <= rem:
			rem -= l.pop(pos + 1)
		if pos + 1 < len(l):
			l[pos + 1] -= rem
		else:
			l[0] = rem
		pos += 1
	return sum(l)

def trans1(l):
	pos = 0
	lenl = len(l)
	pos1 = pos + 1
	while pos1 < lenl and pos < lenl:
		while pos1 < lenl and l[pos] - l[pos1] >= 0:
			l[pos] -= l[pos1]
			l[pos1] = 0
			pos1 += 1
		if pos1 < lenl:
			l[pos1] -= l[pos]
			l[pos] = 0
			pos = pos1
			pos1 += 1
	return sum(l)

def main():
	for _ in range(int(input())):
		num = input()
		l = sorted(list(collections.Counter(input().split()).values()), reverse=True)
		ans = trans(l[:])
		if ans:
			print(min(ans, trans1(l)))
		else:
			print(0)

def transrep():
	for _ in range(int(input())):
		num = int(input())
		l = list(collections.Counter(input().split()).values())
		ml = max(l)
		if ml > num - ml:
			print(ml - num + ml)
		else:
			print(num % 2)

def resmod():

	def solve():
		posc = -1
		negc = 1
		num = int(input())
		l = input().split()
		ifz = False
		maxi = int(l[0])
		for i in range(num - 1):
			maxi = max(maxi, int(l[i + 1]))
			c = int(l[i + 1]) - int(l[i])
			if c == 0:
				if not i:
					ifz = True
					continue
				elif not ifz:
					return -1
			elif ifz:
				return -1
			elif c < 0:
				if negc == 1:
					negc = c
				elif negc != c:
					return -1
			elif c > 0:
				if posc == -1:
					posc = c
				elif posc != c:
					return -1
		if posc == -1 or negc == 1:
			return 0
		mod = posc + -negc
		if mod <= maxi:
			return -1
		return '{0} {1}'.format(mod, posc)
	for _ in range(int(input())):
		print(solve())

def basicdep():

	def findmax(l):
		ans = 0
		res = 0
		for (i, v) in enumerate(l):
			if ans < v:
				res = i
				ans = v
		return [res + 1, ans]

	def roundup(num):
		s = num / 2
		if s != int(s):
			return int(s) + 1
		return int(s)
	for _ in range(int(input())):
		days = []
		(f, d) = map(int, input().split())
		friends = [0] * f
		for i in range(d):
			nowfs = input().split()
			nowff = int(nowfs[1])
			friends[nowff - 1] += 1
			if int(nowfs[0]) > 1:
				days.append([nowff, int(nowfs[2])])
			else:
				days.append([nowff, []])
		maxl = findmax(friends)
		goal = roundup(d)
		if maxl[1] < goal:
			print('YES')
			print(*[i[0] for i in days], sep=' ')
		else:
			pos = 0
			while pos < d and maxl[1] > goal:
				if days[pos][0] == maxl[0] and days[pos][1]:
					days[pos][0] = days[pos][1]
					maxl[1] -= 1
				pos += 1
			if maxl[1] > goal:
				print('NO')
			else:
				print('YES')
				print(*[i[0] for i in days], sep=' ')

def playlist():

	def nextsong(pos):
		while pos + 1 in ans and len(ans) != num:
			pos += 1
			if pos == num:
				pos = 0
		return pos

	def gcf(n, n1):
		if not n:
			return n1
		return gcf(n1, n % n1) if n1 else n
	for _ in range(int(input())):
		num = int(input())
		l = input().split()
		deletel = collections.deque()
		for i in range(num - 1):
			(a, b) = (int(l[i]), int(l[i + 1]))
			if gcf(a, b) == 1:
				deletel.append((i, i + 1))
		if gcf(int(l[-1]), int(l[0])) == 1:
			deletel.append((num - 1, 0))
		ans = dict()
		while deletel and len(ans) != num:
			(a, b) = deletel.popleft()
			if a + 1 in ans or b + 1 in ans:
				continue
			ans[b + 1] = True
			if deletel:
				if deletel[0][0] == b:
					deletel.popleft()
			if b == num - 1:
				n = nextsong(0)
				if gcf(int(l[a]), int(l[n])) == 1:
					deletel.append((a, n))
			else:
				n = nextsong(b + 1)
				if gcf(int(l[a]), int(l[n])) == 1:
					deletel.append((a, n))
		print(len(ans), *ans.keys(), sep=' ')

def shoesandst():
	(students, laces) = map(int, input().split())
	d = collections.defaultdict(list)
	rems = set()
	for _ in range(laces):
		(a, b) = map(int, input().split())
		d[a].append(b)
		d[b].append(a)
		lisa = d[a]
		lisb = d[b]
		la = len(lisa)
		lb = len(lisb)
		if la == 2:
			rems.discard((a, lisa[0]))
		elif la == 1:
			rems.add((a, b))
		if lb == 2:
			rems.discard((b, lisb[0]))
		elif lb == 1:
			rems.add((b, a))
	c = 0
	nextans = set()
	while rems or nextans:
		nextans.clear()
		while rems:
			(a, b) = rems.pop()
			nextans.discard((a, b))
			nextans.discard((b, a))
			d[a].pop()
			d[b].remove(a)
			lb = len(d[b])
			if not lb:
				rems.discard((b, a))
			if lb == 1:
				nextans.add((b, d[b][0]))
		rems = nextans.copy()
		c += 1
	return c
import heapq

def restoreperm():
	for _ in range(int(input())):
		length = int(input())
		maxselect = []
		minselect = []
		ansma = []
		ansmi = []
		last = 0
		for i in input().split():
			i = int(i)
			if i == last:
				ansma.append(-heapq.heappop(maxselect))
				ansmi.append(heapq.heappop(minselect))
			else:
				ansma.append(i)
				ansmi.append(i)
				for num in range(last + 1, i):
					heapq.heappush(maxselect, -num)
					heapq.heappush(minselect, num)
				last = i
		print(*ansmi, sep=' ')
		print(*ansma, sep=' ')

def maxthestring():

	def check(l):
		return tcharacters.issubset(l)
	for _ in range(int(input())):
		s = input().rstrip()
		tcharacters = set(s)
		lsc = len(tcharacters)
		t = ''
		ts = set()
		remainings = collections.deque(s)
		while len(t) < lsc:
			maxc = ''
			for i in range(len(remainings)):
				charac = remainings.popleft()
				if maxc < charac and charac not in ts:
					maxn = remainings.copy()
					maxc = charac
				if check(remainings):
					continue
				t += maxc
				ts.add(maxc)
				break
			remainings = maxn
			tcharacters.discard(maxc)
		print(t)

def maxthestring2():

	def filout(letter, s):
		iff = False
		ans = ''
		for i in s:
			if i != letter and iff:
				ans += i
			elif i == letter:
				iff = True
		return ans
	for _ in range(int(input())):
		s = input().rstrip()
		tcharacters = set(s)
		lsc = len(tcharacters)
		ans = ''
		while lsc:
			maxc = ''
			for i in tcharacters:
				news = filout(i, s)
				if len(set(news)) == lsc - 1 and maxc < i:
					maxc = i
					save = news
			tcharacters.discard(maxc)
			ans += maxc
			s = save
			lsc -= 1
		print(ans)

def maxthestring3():
	for _ in range(int(input())):
		s = input().rstrip()
		lastpos = {v: i for (i, v) in enumerate(s)}
		queue = []
		his = set()
		for i in range(len(s)):
			nowl = s[i]
			if nowl not in his:
				if queue:
					while queue[-1] < nowl and lastpos[queue[-1]] > i:
						his.discard(queue.pop())
						if not queue:
							break
					queue.append(nowl)
					his.add(nowl)
				else:
					queue.append(nowl)
					his.add(nowl)
		print(''.join(queue))

def gcdsum():

	def calc(num):
		dsum = 0
		for i in str(nownum):
			dsum += int(i)
		return dsum

	def gcd(a, b):
		if not a:
			return b
		if not b:
			return a
		return gcd(b, a % b)
	for _ in range(int(input())):
		nownum = int(input())
		dsum = calc(nownum)
		while gcd(dsum, nownum) == 1:
			nownum += 1
			dsum = calc(nownum)
		print(nownum)

def fitbox():
	for _ in range(int(input())):
		(bnum, wid) = map(int, input().split())
		boxes = sorted(list(collections.Counter(input().split()).items()), key=lambda x: int(x[0]), reverse=True)
		ans = 0
		while bnum:
			nwid = wid
			for i in range(len(boxes)):
				boxes[i] = list(boxes[i])
				(w, c) = boxes[i]
				w = int(w)
				while nwid - w >= 0 and c:
					nwid -= w
					c -= 1
					bnum -= 1
				boxes[i][1] = c
			ans += 1
		print(ans)
import sys
sys.setrecursionlimit(10000)

def reflect():

	def recur(cur, plane, dir):
		if cur == 1:
			return 1
		now = l[cur][plane][dir]
		if now != -1:
			return now
		ans = 2
		if dir:
			if cur > 1 and plane > 1:
				ans += recur(cur - 1, plane - 1, 0) - 1
			ans %= num
			if plane < planes:
				ans += recur(cur, plane + 1, 1) - 1
			ans %= num
		else:
			if cur > 1 and plane < planes:
				ans += recur(cur - 1, plane + 1, 1) - 1
			ans %= num
			if plane > 1:
				ans += recur(cur, plane - 1, 0) - 1
			ans %= num
		l[cur][plane][dir] = ans
		return ans
	num = int(1000000000.0 + 7)
	for _ in range(int(input())):
		(planes, begin) = map(int, input().split())
		l = [[[-1] * 2 for _ in range(planes + 1)] for _ in range(begin + 1)]
		print(recur(begin, 1, 1) % num)
mod = int(1000000000.0 + 7)

def iter_solver(N, K):
	dp = [[[-1 for _ in range(2)] for __ in range(K + 1)] for ___ in range(N + 1)]
	for i in range(1, N + 1):
		dp[i][1][0] = dp[i][1][1] = 1
	for k in range(2, K + 1):
		for n in range(N, 0, -1):
			ans = 2
			if n < N:
				ans += dp[n + 1][k][0] - 1
				ans %= mod
			if n > 1:
				ans += dp[n - 1][k - 1][1] - 1
				ans %= mod
			dp[n][k][0] = ans
		for n in range(1, N + 1):
			ans = 2
			if n < N:
				ans += dp[n + 1][k - 1][0] - 1
				ans %= mod
			if n > 1:
				ans += dp[n - 1][k][1] - 1
				ans %= mod
			dp[n][k][1] = ans
	return dp[1][K][0]

def dejavu():
	for _ in range(int(input())):
		s = input().rstrip()
		l = len(s)
		temp = s + 'a'
		if temp[::-1] != temp:
			print('YES')
			print(temp)
			continue
		if l == 1:
			if s == 'a':
				print('NO')
			else:
				print('YES')
				print(s + 'a')
			continue
		for i in range(l - 1, l // 2 - 1, -1):
			d = l - i
			if s[d] != 'a':
				print('YES')
				print(s[:i] + 'a' + s[i:])
				break
		else:
			print('NO')

def bits():
	for _ in range(int(input())):
		num = int(input())
		a = [i for i in input()]
		c1 = a.count('1')
		b = input()
		for i in range(num - 1, -1, -1):
			if a[i] != b[i]:
				if c1 != i + 1 - c1:
					print('NO')
					break
				for i1 in range(i, -1, -1):
					if a[i1] == '1':
						a[i1] = '0'
					else:
						a[i1] = '1'
			if a[i] == '1':
				c1 -= 1
		else:
			print('YES')

def bitsrec():

	def tran(s, num):
		if num % 2:
			if s == '1':
				return '0'
			return '1'
		return s
	for _ in range(int(input())):
		num = int(input())
		a = input()
		b = input()
		flips = 0
		ones = a.count('1')
		for i in range(num - 1, -1, -1):
			if tran(a[i], flips) != b[i]:
				if ones != i - ones + 1:
					print('NO')
					break
				flips += 1
			if tran(a[i], flips) == '1':
				ones -= 1
		else:
			print('YES')

def balance():
	for _ in range(int(input())):
		l = int(input())
		s = input()
		ans = ''
		ans1 = ''
		open = 0
		for i in range(l):
			if not i % 2:
				ans += '('
				if s[i] == '0':
					ans1 += ')'
					open -= 1
				else:
					ans1 += '('
					open += 1
			else:
				ans += ')'
				if s[i] == '0':
					ans1 += '('
					open += 1
				else:
					ans1 += ')'
					open -= 1
			if open < 0:
				print('NO')
				break
		else:
			if not open:
				print('YES')
				print(ans)
				print(ans1)
			else:
				print('NO')

def balanceres():
	for _ in range(int(input())):
		num = int(input())
		s = [i for i in input().rstrip()]
		ones = 0
		ol = []
		zl = []
		for i in range(len(s)):
			if s[i] == '1':
				ones += 1
				ol.append(i)
			else:
				zl.append(i)
		zeros = num - ones
		if zeros % 2 or ones % 2 or s[0] == '0' or (s[-1] == '0'):
			print('NO')
		else:
			pl = ones // 2
			for i in range(ones):
				if i >= pl:
					s[ol[i]] = ')'
				else:
					s[ol[i]] = '('
			diffans = s[:]
			for i in range(zeros):
				p = zl[i]
				if i % 2:
					diffans[p] = '('
					s[p] = ')'
				else:
					diffans[p] = ')'
					s[p] = '('
			print('YES')
			print(*s, sep='')
			print(*diffans, sep='')
import sys

def coloring():
	n = int(input())
	blacks = set()
	whites = set()
	for i1 in range(n):
		for i in range(n):
			if (i + i1) % 2:
				blacks.add((i1 + 1, i + 1))
			else:
				whites.add((i1 + 1, i + 1))
	for i in range(n * n):
		colortochoose = int(input())
		if colortochoose == 1:
			if blacks:
				print(2, *blacks.pop())
			else:
				print(3, *whites.pop())
		elif colortochoose == 2:
			if whites:
				print(1, *whites.pop())
			else:
				print(3, *blacks.pop())
		elif whites:
			print(1, *whites.pop())
		else:
			print(2, *blacks.pop())
		sys.stdout.flush()

def isratedans():
	while True:
		try:
			q = input()
		except EOFError:
			break
		print('NO')
		sys.stdout.flush()

def reflectres():
	for _ in range(int(input())):
		(planes, energy) = map(int, input().split())
		count = [1] * planes
		ans = 1
		energy -= 1
		dir = 1
		while energy:
			if dir:
				cur = 0
				for i in range(planes - 1, -1, -1):
					temp = cur
					cur = (cur + count[i]) % mod
					count[i] = temp
			else:
				cur = 0
				for i in range(planes):
					temp = cur
					cur = cur + count[i] % mod
					count[i] = temp
			ans = (ans + cur) % mod
			dir = 1 - dir
			energy -= 1
		print(ans)
reflectres()


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

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

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		print(1)
		continue
	if n == 1:
		print(2)
		continue
	if k == 2:
		print(n + 1)
		continue
	ans = n + 1
	w = []
	t = 0
	for i in range(n - 1):
		w.append(i + 1)
		t += i + 1
		t %= mod
	ans %= mod
	for i in range(3, k + 1):
		t = 0
		w = w[::-1]
		for j in range(len(w)):
			t += w[j]
			w[j] = t
			t %= mod
			w[j] %= mod
		ans += t
		ans %= mod
	print(ans % mod)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	d = [[0] * 1013 for i in range(1013)]
	ans = 1
	for i in range(1, k + 1):
		for j in range(n + 1):
			if j == 0 or i == 1:
				d[i][j] = 1
			else:
				d[i][j] = (d[i - 1][n - j] + d[i][j - 1]) % 1000000007
	print(d[k][n])


MOD = 10 ** 9 + 7
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		print(1)
	elif k == 2:
		print(n + 1)
	elif n == 1:
		print(2)
	else:
		cur = [i for i in range(1, n)]
		k -= 3
		res = 1 + n + sum(cur)
		while k:
			k -= 1
			nxt = [cur[-1]]
			for i in range(len(cur) - 2, -1, -1):
				nxt.append((nxt[-1] + cur[i]) % MOD)
			res = (res + sum(nxt)) % MOD
			cur = nxt
		print(res)


for _ in range(int(input())):
	(planes, k) = (int(x) for x in input().split())
	if k == 1:
		print(1)
		continue
	if planes == 1:
		print(2)
		continue
	d = {}
	d[k] = 1
	ans = 0
	temp = k
	dp = {}
	planes -= 1
	mod = 1000000007
	for i in range(k, -1, -1):
		dp[i] = []
	for i in range(k, -1, -1):
		for j in range(planes + 1):
			dp[i].append(0)
	dp[k][planes] = 1
	for i in range(k - 1, -1, -1):
		par = 0
		for j in range(planes, 0, -1):
			par = (par % mod + dp[i + 1][j] % mod) % mod
			dp[i][planes - j + 1] = par
	for i in range(k, -1, -1):
		ans = (ans % mod + dp[i][planes] % mod) % mod
	print(ans)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	dp = [[0] * 1013 for i in range(1013)]
	ans = 1
	for i in range(1, k + 1):
		for j in range(n + 1):
			dp[i][j] = 1 if j == 0 or i == 1 else (dp[i - 1][n - j] + dp[i][j - 1]) % (10 ** 9 + 7)
	print(dp[k][n])


import sys
mod = int(10 ** 9 + 7)
for _ in range(int(sys.stdin.readline())):
	(n, k) = map(int, sys.stdin.readline().split())
	if k == 1:
		print(1)
		continue
	if n == 1:
		print(2)
		continue
	now = [0] * (n - 1)
	(now[0], ans, direction) = (1, 0, 1)
	for i in range(k):
		(temp, total) = ([0] * (n - 1), 0)
		if direction == 1:
			for j in range(n - 1):
				total += now[j] % mod
				temp[j] = total
			direction = -direction
		else:
			for j in range(n - 2, -1, -1):
				total += now[j] % mod
				temp[j] = total
			direction = -direction
		now = temp
		ans += total
	print((ans + 1) % mod)


t = int(input())
MOD = 10 ** 9 + 7
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	if k == 1:
		print(1)
		continue
	elif n == 1:
		print(2)
		continue
	counts = [1] * (n - 1)
	size = n - 1
	ans = 2
	left_to_right = True
	for age in range(k - 1):
		ans += sum(counts)
		if left_to_right:
			for i in range(1, size):
				counts[i] = (counts[i - 1] + counts[i]) % MOD
		else:
			for i in range(size - 2, -1, -1):
				counts[i] = (counts[i + 1] + counts[i]) % MOD
		left_to_right = not left_to_right
	print(ans % MOD)


from sys import stdin, gettrace
if gettrace():

	def inputi():
		return input()
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()
MOD = 1000000007

def solve():
	(n, k) = map(int, input().split())
	if k == 1:
		print(1)
		return
	counts = [[0] * (k + 1) for _ in range(n)]
	for i in range(n):
		counts[i][k] = 1
	res = 2
	for j in range(k - 1, 0, -1):
		if (k - j) % 2 == 0:
			for i in range(1, n):
				counts[i][j] = (counts[i - 1][j] + counts[i - 1][j + 1]) % MOD
			res = (res + counts[n - 1][j]) % MOD
		else:
			for i in range(n - 2, -1, -1):
				counts[i][j] = (counts[i + 1][j] + counts[i + 1][j + 1]) % MOD
			res = (res + counts[0][j]) % MOD
	print(res)

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


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
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 RL():
	return map(int, sys.stdin.readline().rstrip().split())

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

def N():
	return int(input())

def A(n):
	return [0] * n

def AI(n, x):
	return [x] * n

def A2(n, m):
	return [[0] * m for i in range(n)]

def G(n):
	return [[] for i in range(n)]

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
mod = 10 ** 9 + 7
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	fact(x, mod)
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa.reverse()

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def floorsum(a, b, c, n):
	if a == 0:
		return b // c * (n + 1)
	if a >= c or b >= c:
		return floorsum(a % c, b % c, c, n) + b // c * (n + 1) + a // c * n * (n + 1) // 2
	m = (a * n + b) // c
	return n * m - floorsum(c, c - b - 1, a, m - 1)

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

def lowbit(n):
	return n & -n

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class ST:

	def __init__(self, arr):
		n = len(arr)
		mx = n.bit_length()
		self.st = [[0] * mx for i in range(n)]
		for i in range(n):
			self.st[i][0] = arr[i]
		for j in range(1, mx):
			for i in range(n - (1 << j) + 1):
				self.st[i][j] = max(self.st[i][j - 1], self.st[i + (1 << j - 1)][j - 1])

	def query(self, l, r):
		if l > r:
			return -inf
		s = (r + 1 - l).bit_length() - 1
		return max(self.st[l][s], self.st[r - (1 << s) + 1][s])

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		seen.add(u)
		for (v, w) in graph[u]:
			if v not in d or d[v] > d[u] + w:
				d[v] = d[u] + w
				heappush(heap, (d[v], v))
	return d

def bell(s, g):
	dis = AI(n, inf)
	dis[s] = 0
	for i in range(n - 1):
		for (u, v, w) in edge:
			if dis[v] > dis[u] + w:
				dis[v] = dis[u] + w
	change = A(n)
	for i in range(n):
		for (u, v, w) in edge:
			if dis[v] > dis[u] + w:
				dis[v] = dis[u] + w
				change[v] = 1
	return dis

def lcm(a, b):
	return a * b // gcd(a, b)

def lis(nums):
	res = []
	for k in nums:
		i = bisect.bisect_left(res, k)
		if i == len(res):
			res.append(k)
		else:
			res[i] = k
	return len(res)

def RP(nums):
	n = len(nums)
	s = set(nums)
	d = {}
	for (i, k) in enumerate(sorted(s), 1):
		d[k] = i
	bi = BIT([0] * (len(s) + 1))
	ans = 0
	for i in range(n - 1, -1, -1):
		ans += bi.query(d[nums[i]] - 1)
		bi.update(d[nums[i]], 1)
	return ans

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def nb(i, j, n, m):
	for (ni, nj) in [[i + 1, j], [i - 1, j], [i, j - 1], [i, j + 1]]:
		if 0 <= ni < n and 0 <= nj < m:
			yield (ni, nj)

def topo(n):
	q = deque()
	res = []
	for i in range(1, n + 1):
		if ind[i] == 0:
			q.append(i)
			res.append(i)
	while q:
		u = q.popleft()
		for v in g[u]:
			ind[v] -= 1
			if ind[v] == 0:
				q.append(v)
				res.append(v)
	return res

@bootstrap
def gdfs(r, p):
	for ch in g[r]:
		if ch != p:
			yield gdfs(ch, r)
	yield None
t = N()
for i in range(t):
	(n, k) = RL()
	dp = A2(k + 1, n + 1)
	for i in range(1, k + 1):
		dp[i][n] = 1
		for j in range(n - 1, -1, -1):
			dp[i][j] = (dp[i][j + 1] + dp[i - 1][n - j]) % mod
	ans = dp[k][0]
	print(ans)


from itertools import accumulate
DIV = 10 ** 9 + 7

def cum_sum(in_list, forward=True):
	if forward:
		for i in range(1, len(in_list)):
			in_list[i] += in_list[i - 1]
			in_list[i] %= DIV
	else:
		for i in range(len(in_list) - 2, -1, -1):
			in_list[i] += in_list[i + 1]
			in_list[i] %= DIV

def count_planar(n, k):
	if k == 1:
		print(1)
	elif n == 1:
		print(2)
	else:
		cnt = 2
		mem = [1] * (n - 1)
		for i in range(k - 1):
			if i % 2 == 0:
				cum_sum(mem, forward=True)
				cnt += mem[-1]
			else:
				cum_sum(mem, forward=False)
				cnt += mem[0]
		print(cnt % (10 ** 9 + 7))
num = int(input())
for i in range(num):
	(n, k) = [int(el) for el in input().split()]
	count_planar(n, k)


import bisect
import collections
import functools
import heapq
import itertools
import math
import random
import sys
input = sys.stdin.readline
ri = lambda : int(input())
rf = lambda : list(map(float, input().split()))
rl = lambda : list(map(int, input().split()))
rs = lambda : input().rstrip()
MOD = 10 ** 9 + 7

def solve_case():
	(n, k) = rl()
	dp = [[0] * (k + 1) for _ in range(n + 1)]
	for j in range(1, k + 1):
		total = 1
		for i in range(n + 1):
			dp[i][j] = total % MOD
			if i < n:
				total += dp[n - 1 - i][j - 1]
	print(dp[n][k])
T = ri()
for ti in range(1, T + 1):
	solve_case()


def helper(n, k):
	if k == 1:
		return 1
	mod = 1000000007
	res = n + 1
	k -= 1
	dp = [1] * n
	flag = -1
	while k > 1:
		ndp = [0] * n
		if flag == -1:
			for i in range(n - 2, -1, -1):
				ndp[i] = (dp[i + 1] + ndp[i + 1]) % mod
			flag = 1
		elif flag == 1:
			for i in range(1, n):
				ndp[i] = (dp[i - 1] + ndp[i - 1]) % mod
			flag = -1
		res = (res + sum(ndp)) % mod
		dp = ndp
		k -= 1
	return res
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(helper(n, k))


def main():
	allans = []
	t = int(input())
	for _ in range(t):
		(n, k) = readIntArr()
		dp = makeArr(0, [k + 1, n + 1])
		for i in range(1, k + 1):
			dp[i][0] = 1
		for j in range(n + 1):
			dp[1][j] = 1
		for i in range(2, k + 1):
			for j in range(1, n + 1):
				dp[i][j] = (dp[i][j - 1] + dp[i - 1][n - j]) % MOD
		ans = dp[k][n]
		allans.append(ans)
	multiLineArrayPrint(allans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultVal, dimensionArr):
	dv = defaultVal
	da = dimensionArr
	if len(da) == 1:
		return [dv for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(x, y):
	print('? {} {}'.format(x, y))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(ans))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


m = 1000000007
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	mas = [[0] * 1001 for i in range(1001)]
	for i in range(1, k + 1):
		for j in range(n + 1):
			if i == 1 or j == 0:
				mas[i][j] = 1
			else:
				mas[i][j] = (mas[i - 1][n - j] + mas[i][j - 1]) % m
	print(mas[k][n])


t = int(input())
mod = 1000000007
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	if k == 1:
		print(1)
		continue
	if n == 1:
		print(2)
		continue
	a = [1] * n
	total = 1
	total += n
	k -= 1
	r = True
	if k == 1:
		print(total)
	else:
		for i in range(k - 1):
			temp = [0] * n
			if r:
				for j in range(n - 2, -1, -1):
					temp[j] = (temp[j + 1] + a[j + 1]) % mod
					total = (total + temp[j + 1] + a[j + 1]) % mod
			else:
				for j in range(1, n):
					temp[j] = (temp[j - 1] + a[j - 1]) % mod
					total = (total + temp[j - 1] + a[j - 1]) % mod
			r = not r
			a = temp
		print(total)


import sys, io, os
input = lambda : sys.stdin.readline().encode()
read = lambda : map(int, input().split())
M = 10 ** 9 + 7
out = []
for _ in range(int(input())):
	(n, k) = read()
	c = [0] * n
	c[0] = 1
	t = 1
	for i in range(k - 1):
		if i < 1:
			t += 1
		s = 0
		for j in range(n):
			s += c[j]
			if s >= M:
				s -= M
			if j:
				c[j - 1] = s
				t += s
				if t >= M:
					t -= M
		c[-1] = 0
		c = c[::-1]
	out.append(str(t))
print('\n'.join(out))


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')
mod = 10 ** 9 + 7
from itertools import accumulate

def pre(a):
	return list(accumulate(a, lambda a, b: (a + b) % mod))

def suff(a):
	return list(reversed(list(accumulate(a[::-1], lambda a, b: (a + b) % mod))))
for _ in range(rn()):
	(n, k) = rns()
	ans = 1
	nums = (n - 1) * [1]
	for i in range(k - 1):
		ans += sum(nums)
		if i % 2 == 0:
			nums = suff(nums)
		else:
			nums = pre(nums)
		ans %= mod
	if k > 1:
		ans += 1
		ans %= mod
	print(ans)


MOD = int(1000000000.0 + 7)

def solve(k, n):
	global dp
	for i in range(1, k + 1):
		for j in range(1, n + 1):
			dp[i][j] = (dp[i][j - 1] + dp[i - 1][n - j]) % MOD
	return dp[k][n]
for _ in range(int(input())):
	(n_, k_) = map(int, input().split())
	dp = [[0 for i in range(n_ + 1)] for j in range(k_ + 1)]
	for i in range(k_ + 1):
		dp[i][0] = 1
	dp[0][0] = 0
	print(solve(k_, n_))


def ss(n, k):
	dp = [[0 for _ in range(n + 1)] for _ in range(k + 1)]
	for i in range(n + 1):
		dp[0][i] = 1
	for i in range(k + 1):
		dp[i][0] = 1
	for d in range(1, k + 1):
		for i in range(n):
			dp[d][i + 1] = (dp[d][i] + dp[d - 1][n - i - 1]) % 1000000007
	return dp[k - 1][n]
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(ss(n, k))


from sys import stdin
input = stdin.readline
MOD = 1000000007
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	dp = [[0] * (n + 1) for _ in range(k)]
	for r in range(1, k):
		for c in range(1, n + 1):
			dp[r][c] = (dp[r][c - 1] + dp[r - 1][n - c] + 1) % MOD
	ans = (dp[-1][-1] + 1) % MOD
	print(ans)


import sys
input = sys.stdin.readline

def solve():
	(n, k) = map(int, input().split())
	m = 10 ** 9 + 7
	dp = []
	for i in range(0, 1013):
		dp.append([0] * 1013)
	for i in range(1, k + 1):
		for j in range(0, n + 1):
			if j == 0 or i == 1:
				dp[i][j] = 1
			else:
				dp[i][j] = (dp[i - 1][n - j] + dp[i][j - 1]) % m
	return dp[k][n]
for _ in range(int(input())):
	print(solve())


import sys
sys.setrecursionlimit(10000)
mod = 10 ** 9 + 7

def solve(curr, left):
	if dp[curr][left] != -1:
		return dp[curr][left]
	if left == 1:
		return 1
	if curr == 0:
		if dp[curr][left] != -1:
			return dp[curr][left]
		dp[curr][left] = (1 + solve(curr + 1, left)) % mod
		return dp[curr][left]
	elif curr == n:
		return 1
	ans1 = solve(n - curr, left - 1) % mod
	ans2 = solve(curr + 1, left) % mod
	dp[curr][left] = (ans1 + ans2) % mod
	return dp[curr][left]
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	dp = [[-1 for i in range(k + 1)] for j in range(n + 1)]
	ans = solve(0, k)
	print(ans)


import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	dp = [[1 for i in range(1001)] for j in range(1001)]
	for i in range(1, k + 1):
		for j in range(n + 1):
			if i == 1 or j == 0:
				continue
			else:
				dp[i][j] = (dp[i][j - 1] + dp[i - 1][n - j]) % mod
	print(dp[k][n] % mod)


import os
import sys
from io import BytesIO, IOBase

def main():
	mod = 10 ** 9 + 7
	T = int(input())
	for _ in range(T):
		(n, k) = map(int, input().split())
		if k == 1:
			print(1)
		elif n == 1:
			print(2)
		else:
			DP = [[0 for i in range(n)] for j in range(k + 1)]
			for i in range(n - 1):
				DP[k][i] = 1
			ans = 2
			val = k - 1
			while True:
				if val == 0:
					break
				for i in range(n - 2, -1, -1):
					DP[val][i] = (DP[val + 1][i] + DP[val][i + 1]) % mod
				ans = (ans + DP[val][0]) % mod
				val = val - 1
				if val == 0:
					break
				for i in range(n - 1):
					DP[val][i] = (DP[val + 1][i] + DP[val][i - 1]) % mod
				ans = (ans + DP[val][-2]) % mod
				val = val - 1
				if val == 0:
					break
			print(ans)
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()


from io import BytesIO, IOBase
import sys
import math
import os
from collections import defaultdict
from math import ceil
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 mint():
	return map(int, input().split())

def mfloat():
	return map(float, input().split())
mod = int(1000000000.0) + 7

def recurse(forward, backward, decay, dp):
	if dp[forward][decay]:
		return dp[forward][decay]
	if forward == 0 or decay == 1:
		dp[forward][decay] = 1
		return 1
	dp[forward][decay] = (recurse(backward, forward, decay - 1, dp) + recurse(forward - 1, backward + 1, decay, dp)) % mod
	return dp[forward][decay]

def solve():
	(n, k) = mint()
	dp = [[0] * (k + 1) for i in range(n + 1)]
	print(recurse(n, 0, k, dp))

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


mod = 10 ** 9 + 7
for t in range(int(input())):
	(n, k) = map(int, input().split())
	n -= 1
	state = [1] * n
	total = 1 if k == 1 else 2
	nextState = [0] * n
	for _ in range(k - 1):
		temp = 0
		for i in range(n):
			temp = (temp + state[i]) % mod
			nextState[n - i - 1] = temp
		total = (total + temp) % mod
		state = nextState.copy()
	print(total)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	MOD = 1000000007
	dp = [[0 for x in range(1010)] for y in range(1010)]
	for l in range(k + 1):
		for m in range(n + 1):
			if l == 1:
				dp[l][m] = 1
			elif m == 0:
				dp[l][m] = 1
			else:
				dp[l][m] = (dp[l][m - 1] + dp[l - 1][n - m]) % MOD
	print(dp[k][n])


import sys
from sys import stdout
import bisect as bi
import math
from collections import defaultdict as dd
from types import GeneratorType
from collections import deque
from heapq import heapify, heappush, heappop
from itertools import permutations
import random
input = sys.stdin.readline
mo = 10 ** 9 + 7
MOD = 998244353

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input().strip()

def inin():
	return int(input())
mod = 10 ** 9 + 7
ans = []

def solve(n, k):
	d = 0
	res = 0
	cond = [0 for i in range(n + 1)]
	cond[0] = 1
	for i in range(k):
		if not d:
			for j in range(1, n + 1):
				cond[j] += cond[j - 1]
				cond[j] %= mod
			res += cond[n]
			res %= mod
			cond[n] = 0
			d = 1
		else:
			for j in range(n - 1, -1, -1):
				cond[j] += cond[j + 1]
				cond[j] %= mod
			res += cond[0]
			res %= mod
			cond[0] = 0
			d = 0
	return res
for _ in range(inin()):
	global N, K
	(N, K) = cin()
	print(solve(N, K) % mod)

def msb(n):
	n |= n >> 1
	n |= n >> 2
	n |= n >> 4
	n |= n >> 8
	n |= n >> 16
	n |= n >> 32
	n |= n >> 64
	return n - (n >> 1)

def pref(a, n, f):
	pre = [0] * n
	if f == 0:
		pre[0] = a[0]
		for i in range(1, n):
			pre[i] = a[i] + pre[i - 1]
	else:
		pre[-1] = a[-1]
		for i in range(n - 2, -1, -1):
			pre[i] = pre[i + 1] + a[i]
	return pre

def kadane(A):
	maxSoFar = maxEndingHere = start = end = beg = 0
	for i in range(len(A)):
		maxEndingHere = maxEndingHere + A[i]
		if maxEndingHere < 0:
			maxEndingHere = 0
			beg = i + 1
		if maxSoFar < maxEndingHere:
			maxSoFar = maxEndingHere
			start = beg
			end = i
	return (maxSoFar, start, end)

def modFact(n, p):
	if n < 0:
		return 0
	if n >= p:
		return 0
	result = 1
	for i in range(1, n + 1):
		result = result * i % p
	return result

def ncr(n, r, p):
	if n < r or n < 0:
		return 0
	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 bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc


module = 10 ** 9 + 7
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		print(1)
	elif n == 1:
		print(2)
	else:
		ans = 2
		table = [[1] * (n - 1)]
		left = 1
		while k != 1:
			if left:
				table.append([table[-1][-1]])
				for num in list(reversed(table[-2]))[1:]:
					table[-1].append(table[-1][-1] + num)
				table[-1].reverse()
				for ind in range(n - 1):
					table[-1][ind] %= module
				left = 0
			else:
				table.append([table[-1][0]])
				for num in table[-2][1:]:
					table[-1].append(table[-1][-1] + num)
				for ind in range(n - 1):
					table[-1][ind] %= module
				left = 1
			k -= 1
		if left:
			start = -2
			ans += table[-1][-1]
		else:
			start = -1
		for (num, ind) in enumerate(range(start, -len(table), -1)):
			ans = (ans + table[ind][0 if num % 2 == 0 else -1]) % module
		print(ans)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
md = 10 ** 9 + 7
(t,) = I()
for _ in range(t):
	(n, k) = I()
	if n == 1:
		print(1 if k == 1 else 2)
	elif k == 1:
		print(1)
	else:
		an = 1
		arr = [0] * n
		di = 1
		arr[0] = 1
		while k > 1:
			pos = [0] * n
			an = (an + sum(arr)) % md
			if di:
				for i in range(1, n):
					pos[i] += arr[i - 1] + pos[i - 1]
					pos[i] %= md
				arr = list(pos)
				di = 0
			else:
				for i in range(n - 2, -1, -1):
					pos[i] += arr[i + 1] + pos[i + 1]
					pos[i] %= md
				arr = list(pos)
				di = 1
			k -= 1
		an = (an + sum(arr)) % md
		print(an)


mod = int(1000000000.0 + 7)

def iter_solver(N, K):
	dp = [[[-1 for _ in range(2)] for __ in range(K + 1)] for ___ in range(N + 1)]
	for i in range(1, N + 1):
		dp[i][1][0] = dp[i][1][1] = 1
	for k in range(2, K + 1):
		for n in range(N, 0, -1):
			ans = 2
			if n < N:
				ans += dp[n + 1][k][0] - 1
				ans %= mod
			if n > 1:
				ans += dp[n - 1][k - 1][1] - 1
				ans %= mod
			dp[n][k][0] = ans
		for n in range(1, N + 1):
			ans = 2
			if n < N:
				ans += dp[n + 1][k - 1][0] - 1
				ans %= mod
			if n > 1:
				ans += dp[n - 1][k][1] - 1
				ans %= mod
			dp[n][k][1] = ans
	return dp[1][K][0]
t = int(input())
while t > 0:
	t -= 1
	(n, k) = list(map(int, input().split()))
	print(iter_solver(n, k))


mod = 10 ** 9 + 7

def solve(n, k):
	left = [[0] * n for _ in range(k + 1)]
	right = [[0] * n for _ in range(k + 1)]
	res = 1
	for i in range(n):
		right[k][i] = 1
	for a in range(k - 1, 0, -1):
		for i in range(1, n):
			right[a][i] = left[a + 1][i - 1] + right[a][i - 1]
			right[a][i] %= mod
		res += sum(left[a + 1])
		res %= mod
		for i in range(n - 2, -1, -1):
			left[a][i] = right[a + 1][i + 1] + left[a][i + 1]
			left[a][i] %= mod
		res += sum(right[a + 1])
		res %= mod
	return res
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(solve(n, k))


from sys import stdin
MOD = int(1000000000.0 + 7)

def solve(tc):
	(n, k) = map(int, stdin.readline().split())
	if n == 1:
		if k == 1:
			print(1)
		else:
			print(2)
		return
	mem = [0 for i in range(k + 1)]
	planes = [1 for i in range(n)]
	mem[1] = 1
	for i in range(2, k + 1):
		mem[i] = mem[i - 1]
		for j in range(n):
			mem[i] += planes[j]
			mem[i] %= MOD
		if i & 1:
			cum = planes[0]
			planes[0] = 0
			for j in range(1, n):
				tmp = planes[j]
				planes[j] = cum
				cum += tmp
				cum %= MOD
		else:
			cum = planes[n - 1]
			planes[n - 1] = 0
			for j in range(n - 2, -1, -1):
				tmp = planes[j]
				planes[j] = cum
				cum += tmp
				cum %= MOD
	print(mem[k])
tcs = 1
tcs = int(stdin.readline().strip())
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


import sys
input = sys.stdin.readline

def I():
	return input().strip()

def II():
	return int(input().strip())

def LI():
	return [*map(int, input().strip().split())]
import string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, combinations, groupby
MOD = 10 ** 9 + 7
for _ in range(II()):
	(n, k) = LI()
	if k == 1:
		print(1)
		continue
	if n == 1:
		print(2)
		continue
	n -= 1
	arr = [0] * (k - 1)
	ans = n + 2
	for i in range(k - 1):
		if i == 0:
			arr[i] = [1] * n
			continue
		arr[i] = [0] * n
	for i in range(1, k - 1):
		if i % 2 == 0:
			s = 0
			for j in range(n):
				s = (s + arr[i - 1][j]) % MOD
				arr[i][j] = s
				ans = (ans + s) % MOD
		else:
			s = 0
			for j in range(n - 1, -1, -1):
				s = (s + arr[i - 1][j]) % MOD
				arr[i][j] = s
				ans = (ans + s) % MOD
	print(ans % MOD)


from sys import stdin, stdout
input = stdin.readline
mod = 10 ** 9 + 7

def f(l, r, k):
	assert l + r == n
	if r == 0:
		return 1
	if k == 1:
		return 1
	if dp[l][k]:
		return dp[l][k]
	ans = f(r, l, k - 1) + f(l + 1, r - 1, k)
	ans %= mod
	dp[l][k] = ans
	return ans
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	dp = [[0 for i in range(k + 1)] for j in range(n + 1)]
	print(f(0, n, k))


import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7
t = int(input())
for tests in range(t):
	(n, k) = map(int, input().split())
	if k == 1:
		print(1)
		continue
	if n == 1:
		print(2)
		continue
	ANS = 1
	DP = [1] * n
	for i in range(k - 1):
		NDP = [0] * n
		if i % 2 == 0:
			S = 0
			for j in range(n):
				S += DP[j]
				S %= mod
				if j != n - 1:
					NDP[j + 1] = S
			ANS += S
		else:
			S = 0
			for j in range(n - 1, -1, -1):
				S += DP[j]
				S %= mod
				if j != 0:
					NDP[j - 1] = S
			ANS += S
		DP = NDP
	print(ANS % mod)


MOD = 10 ** 9 + 7

def solve(N, K):
	last_dp = [1] * (N + 1)
	ans = 1
	turn = 0
	for _ in range(K - 1, 0, -1):
		dp = [0] * (N + 1)
		if turn == 0:
			for j in range(N - 1, -1, -1):
				dp[j] = last_dp[j] + dp[j + 1]
			ans += dp[0]
		else:
			for j in range(1, N + 1, 1):
				dp[j] = last_dp[j] + dp[j - 1]
			ans += dp[N]
		turn = 1 - turn
		last_dp = dp
	return ans % MOD
T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	print(solve(N, K))


from sys import stdin
mod = pow(10, 9) + 7
t = int(stdin.readline().rstrip())
matrix_l = [[0] * 1001 for _ in range(1000)]
matrix_r = [[0] * 1001 for _ in range(1000)]
for _ in range(t):
	(n, k) = list(map(int, stdin.readline().rstrip().split()))
	for i in range(k):
		matrix_l[i][0] = 1
		matrix_r[i][0] = 1
	for i in range(n + 1):
		matrix_l[0][i] = 1
		matrix_r[0][i] = 1
	for i in range(1, k):
		for j in range(1, n + 1):
			matrix_l[i][j] = (matrix_l[i][j - 1] + matrix_r[i - 1][n - j]) % mod
			matrix_r[i][j] = (matrix_l[i - 1][n - j] + matrix_r[i][j - 1]) % mod
	print(matrix_r[k - 1][n])


import sys
input = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
for t in range(int(input())):
	(N, K) = map(int, input().split())
	DP = [[[-1, -1, -1] for j in range(N + 2)] for i in range(K + 2)]
	for k in range(1, K + 1):
		for x in range(N, -2, -1):
			y = 1
			if x == N or k == 1 or x == -1:
				DP[k][x][y] = 1
				continue
			DP[k][x][y] = DP[k][x + y][y] + DP[k - 1][x - y][-y]
			if DP[k][x][y] >= mod:
				DP[k][x][y] -= mod
		for x in range(-1, N + 1):
			y = -1
			if x == N or k == 1 or x == -1:
				DP[k][x][y] = 1
				continue
			DP[k][x][y] = DP[k][x + y][y] + DP[k - 1][x - y][-y]
			if DP[k][x][y] >= mod:
				DP[k][x][y] -= mod
	print(DP[K][0][1])


import sys
input = sys.stdin.readline

def fun(x, y):
	rem = 1000000007
	return (x % rem + y % rem) % rem
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n == 1:
		if k > 1:
			print(2)
		else:
			print(1)
	else:
		left = [0] * (n - 1)
		right = [0] * (n - 1)
		left[0] = 1
		count = 0
		ans = 0
		for i in range(k):
			if count % 2 == 0:
				tem = 0
				for j in range(n - 1):
					tem = fun(left[j], tem)
					right[j] = tem
				ans = fun(ans, tem)
			else:
				tem = 0
				for j in range(n - 2, -1, -1):
					tem = fun(right[j], tem)
					left[j] = tem
				ans = fun(ans, tem)
			count += 1
		if k > 1:
			ans += 1
		print(ans)


R = range
for s in [*open(0)][1:]:
	(n, k) = map(int, s.split())
	D = [[1] * (n + 1)] + [[1] + n * [0] for _ in R(k)]
	for d in R(1, k):
		for i in R(n):
			D[d][i + 1] = (D[d][i] + D[d - 1][n - i - 1]) % (10 ** 9 + 7)
	print(D[k - 1][n])


mod = 10 ** 9 + 7

def abhi(n, k):
	if k <= 0:
		return 0
	elif n <= 0 and k > 0:
		return 1
	elif dp[n][k] != -1:
		return dp[n][k] % mod
	else:
		a = abhi(s - n, k - 1) % mod
		b = abhi(n - 1, k) % mod
		if s - n >= 0:
			dp[s - n][k - 1] = a % mod
		if n >= 1:
			dp[n - 1][k] = b % mod
		return (a + b) % mod
for i in range(int(input())):
	(s, k) = map(int, input().split())
	dp = [[-1 for i in range(1005)] for j in range(1005)]
	print(abhi(s, k) % mod)


import sys
input = sys.stdin.readline
MOD = 1000000007
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		print(1)
		continue
	if n == 1:
		print(2)
		continue
	dp1 = [[0 for i in range(n + 2)] for j in range(k + 1)]
	dp2 = [[0 for i in range(n + 2)] for j in range(k + 1)]
	s1 = [[0 for i in range(n + 2)] for j in range(k + 1)]
	s2 = [[0 for i in range(n + 2)] for j in range(k + 1)]
	ans = 1
	for j in range(1, n + 1):
		dp1[k][j] = 1
		s1[k][j] = j
	for i in range(k - 1, 0, -1):
		for j in range(1, n + 1):
			dp1[i][j] = (s2[i + 1][1] - s2[i + 1][j] + MOD) % MOD
			s1[i][j] = (s1[i][j - 1] + dp1[i][j]) % MOD
		for j in range(n, 0, -1):
			dp2[i][j] = (s1[i + 1][n] - s1[i + 1][j] + MOD) % MOD
			s2[i][j] = (s2[i][j + 1] + dp2[i][j]) % MOD
		ans = (ans + s1[i + 1][n] + s2[i + 1][1]) % MOD
	print(ans)


def Sort(sub_li):
	return sorted(sub_li, key=lambda x: x[1])
import math
n = int(input())
mod = 10 ** 9 + 7
for i in range(0, n):
	o = input().rstrip().split(' ')
	N = int(o[0])
	K = int(o[1])
	if K == 1:
		print(1)
	elif N == 1:
		print(2)
	else:
		ans = 1 + N
		K -= 1
		L = [0] * (N - 1)
		if K > 1:
			for j in range(0, N - 1):
				L[j] = (N - j - 1) % mod
				ans += L[j]
			I = 0
			K -= 1
			ans %= mod
			while K > 1:
				if I % 2 == 0:
					I += 1
					for j in range(0, len(L)):
						if j == 0:
							ans = (ans + L[j]) % mod
							continue
						else:
							L[j] = (L[j] + L[j - 1]) % mod
							ans = (ans + L[j]) % mod
				else:
					I += 1
					for j in range(len(L) - 1, -1, -1):
						if j == len(L) - 1:
							ans = (ans + L[j]) % mod
							continue
						else:
							L[j] = (L[j] + L[j + 1]) % mod
							ans = (ans + L[j]) % mod
				ans %= mod
				K -= 1
			print(ans % mod)
		else:
			print(ans % mod)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if k == 1:
		print(1)
	elif k == 2:
		print(n + 1)
	else:
		a = [i for i in range(n - 1, 0, -1)]
		s = n + 1
		for i in a:
			s += i
		(d, k) = (1, k - 2)
		while k > 1:
			if d:
				for i in range(1, len(a)):
					a[i] = (a[i] + a[i - 1]) % 1000000007
			else:
				for i in range(len(a) - 2, -1, -1):
					a[i] = (a[i] + a[i + 1]) % 1000000007
			k -= 1
			d = 1 - d
			for i in a:
				s += i
			if s > 1000000007:
				s = s % 1000000007
		print(s)


def sol(n, k):
	m = 1000000007
	if k == 1:
		return 1
	elif n == 1:
		return 2
	arr = [[0 for j in range(n)] for p in range(2)]
	sum = 0
	if k < 3:
		return (sum + n + 1) % m
	for i in range(n):
		sum += i
		arr[(k - 2) % 2][n - i - 1] = i
	k = k - 2
	buf_sum = sum
	while k > 1:
		buf = storage = 0
		ind = k % 2
		ind1 = (k + 1) % 2
		for i in range(n):
			buf += arr[ind][n - i - 1]
			buf %= m
			arr[ind1][i] = buf_sum - buf
			sum += buf_sum - buf
			storage += buf_sum - buf
			storage %= m
			sum = sum % m
		k -= 1
		buf_sum = storage
	return sum + n + 1
for t in range(int(input())):
	data = input().split()
	n = int(data[0])
	k = int(data[1])
	print(sol(n, k))


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

def sol():
	C = 10 ** 9 + 7
	(n, k) = putin()
	if k == 1:
		print(1)
		return
	if n == 1:
		print(2)
		return
	D = []
	for i in range(k):
		D.append([0] * n)
	for i in range(n):
		D[0][i] = 1
	for i in range(1, k):
		D[i][n - 1] = D[i - 1][1] + 1
		D[i][n - 1] %= C
		for j in range(n - 2, 0, -1):
			D[i][j] = D[i][j + 1] + D[i - 1][n - j]
			D[i][j] %= C
		D[i][0] = 1 + D[i][1]
		D[i][0] %= C
	print(D[k - 1][0])
for iter in range(int(input())):
	sol()


mod = int(1000000000.0 + 7)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		print(1)
		continue
	if n == 1:
		print(2)
		continue
	ans = 1
	n -= 1
	a = [1 for _ in range(n)]
	while True:
		cursum = 0
		for i in range(n):
			a[i] += cursum
			cursum = a[i]
		ans += cursum
		k -= 1
		if k == 1:
			break
		cursum = 0
		for i in range(n - 1, -1, -1):
			a[i] += cursum
			cursum = a[i]
		ans += cursum
		k -= 1
		if k == 1:
			break
	print((ans + 1) % mod)


import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	dp = [[0] * (n + 1) for _ in range(k + 1)]
	for i in range(1, k + 1):
		cur = 1
		for j in range(n + 1):
			dp[i][j] = cur
			if j < n:
				cur = (cur + dp[i - 1][n - 1 - j]) % mod
	print(dp[-1][-1])


from __future__ import division, print_function
import sys
import collections
import math
import bisect
import heapq
inf = sys.maxsize

def get_ints():
	return map(int, input().strip().split())

def get_array():
	return list(map(int, input().strip().split()))
mod = 1000000007
MOD = 998244353

def main():
	for _ in range(int(input())):
		(n, k) = get_ints()
		dp = [[0 for i in range(1005)] for j in range(1005)]
		for i in range(1, k + 1):
			for j in range(n + 1):
				if i == 1:
					dp[i][j] = 1
				elif j == 0:
					dp[i][j] = 1
				else:
					dp[i][j] = (dp[i][j - 1] % mod + dp[i - 1][n - j] % mod) % mod
		print(dp[k][n] % mod)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	dp = [[0 for i in range(1002)] for i in range(1002)]
	for i in range(k + 1):
		for j in range(n + 1):
			if i == 1 or j == 0:
				dp[i][j] = 1
			else:
				dp[i][j] = (dp[i][j - 1] + dp[i - 1][n - j]) % 1000000007
	print(dp[k][n])


for i in range(int(input())):
	(n, k) = map(int, input().split())
	dp = [[0] * n for j in range(k - 1)]
	if k > 1:
		for j in range(n):
			dp[0][j] = 1
	for j in range(1, k - 1):
		if j % 2 == 1:
			for l in range(1, n):
				dp[j][l] = (dp[j][l - 1] + dp[j - 1][l - 1]) % 1000000007
		else:
			for l in range(n - 2, -1, -1):
				dp[j][l] = (dp[j][l + 1] + dp[j - 1][l + 1]) % 1000000007
	sumo = 0
	for j in range(k - 1):
		for l in range(n):
			sumo = (sumo + dp[j][l]) % 1000000007
	print((1 + sumo) % 1000000007)


import sys
from math import *
import threading
from itertools import count
from pprint import pprint
from collections import defaultdict
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(300000)
mod = 10 ** 9 + 7
inf = 10 ** 15
decision = ['NO', 'YES']
yes = 'YES'
no = 'NO'
import os
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 npr(n, r):
	return factorial(n) // factorial(n - r) if n >= r else 0

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

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

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

def prod(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def sumk(a, b):
	print('called for', a, b)
	ans = a * (a + 1) // 2
	ans -= b * (b + 1) // 2
	return ans
karmanya = 1
for _ in range(int(input()) if karmanya else 1):
	(n, k) = map(int, input().split())
	dp = [[0 for j in range(1002)] for i in range(1002)]
	for i in range(k + 1):
		for j in range(n + 1):
			if i == 1 or j == 0:
				dp[i][j] = 1
			else:
				dp[i][j] = (dp[i][j - 1] + dp[i - 1][n - j]) % mod
	print(dp[k][n])


import sys

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

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

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

def LI2():
	return list(map(int, sys.stdin.readline().rstrip()))

def S():
	return sys.stdin.readline().rstrip()

def LS():
	return list(sys.stdin.readline().rstrip().split())

def LS2():
	return list(sys.stdin.readline().rstrip())
t = I()
mod = 10 ** 9 + 7
for _ in range(t):
	(n, k) = MI()
	if k == 1:
		ans = 1
	elif k == 2:
		ans = 1 + n
	else:
		ans = 1 + n
		X = [i for i in range(n - 1, 0, -1)]
		for i in range(k - 2):
			ans += sum(X)
			ans %= mod
			if i % 2 == 0:
				for j in range(1, n - 1):
					X[j] += X[j - 1]
					X[j] %= mod
			else:
				for j in range(n - 3, -1, -1):
					X[j] += X[j + 1]
					X[j] %= mod
	print(ans)


MAX_N = 1001
MOD_N = 1000000007
t = int(input())
ans = [[-1 for _ in range(MAX_N)] for _ in range(MAX_N)]

def dp(n, k, total_k):
	if n == 1 or k == 0:
		ans[n][k] = 1
		return ans[n][k]
	if ans[n][k] != -1:
		return ans[n][k]
	ans[n][k] = (dp(n - 1, total_k - k, total_k) + dp(n, k - 1, total_k)) % MOD_N
	return ans[n][k]
while t > 0:
	(n, k) = map(int, input().split())
	ans = [[1] * (n + 1)] + [[1] * (n + 1)] + [[1] + [0] * n for _ in range(k)]
	for i in range(2, k + 1):
		for j in range(1, n + 1):
			ans[i][j] = (ans[i - 1][n - j] + ans[i][j - 1]) % MOD_N
	print(ans[k][n])
	t -= 1


import sys
MOD = 1000000007

def read_ints():
	return [int(i) for i in sys.stdin.readline().strip().split()]

def read_int():
	return int(sys.stdin.readline().strip())

def solve(n, k):
	if k == 1:
		return 1
	particles = 1
	dp = [1] * n
	while k > 1:
		particles += sum(dp)
		particles %= MOD
		k -= 1
		tot = 0
		dp2 = [0] * n
		for i in range(n):
			dp2[i] = tot
			tot += dp[i]
			tot %= MOD
		dp2.reverse()
		dp = dp2[:]
	return particles
t = read_int()
for i in range(t):
	(n, k) = read_ints()
	print(solve(n, k))


import sys
from collections import deque
md = 10 ** 9 + 7
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	dp = [[0] * 1001 for j in range(1001)]
	for voz in range(1, k + 1):
		for pan in range(n + 1):
			if voz == 1 or pan == 0:
				dp[voz][pan] = 1
			else:
				dp[voz][pan] = (dp[voz][pan - 1] % md + dp[voz - 1][n - pan] % md) % md
	print(dp[k][n] % md)


import math
import sys
import collections
import bisect
import heapq
testcases = int(sys.stdin.readline())
for _ in range(testcases):
	arr = list(map(int, sys.stdin.readline().strip().split()))
	n = arr[0]
	k = arr[1]
	if k == 1:
		res = 1
	elif n == 1:
		res = 2
	else:
		res = 1 + n
		arr = [1] * n
		pref = [0] * n
		for j in range(1, n):
			pref[j] = pref[j - 1] + arr[j - 1]
		for i in range(k - 2, 0, -1):
			arr = list(reversed(pref))
			for j in range(1, n):
				pref[j] = pref[j - 1] + arr[j - 1]
			res += pref[-1]
	print(res % (10 ** 9 + 7))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	dp = [[[-1 for i in range(2)] for j in range(k + 1)] for l in range(n + 1)]
	for i in range(1, n + 1):
		(dp[i][1][0], dp[i][1][1]) = (1, 1)
	for i in range(2, k + 1):
		for j in range(n, 0, -1):
			loc = 2
			if j < n:
				loc += dp[j + 1][i][0] - 1
			if j > 1:
				loc += dp[j - 1][i - 1][1] - 1
			dp[j][i][0] = loc % (10 ** 9 + 7)
		for j in range(1, n + 1):
			loc = 2
			if j < n:
				loc += dp[j + 1][i - 1][0] - 1
			if j > 1:
				loc += dp[j - 1][i][1] - 1
			dp[j][i][1] = loc % (10 ** 9 + 7)
	print(dp[1][k][0])


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')
sys.setrecursionlimit(3 * 10000 + 10)
tc = 1
tc = int(input())
for test in range(1, tc + 1):
	(N, K) = inp()
	dp = [[[0, 0] for i in range(N + 1)] for j in range(K + 1)]
	for i in range(1, N + 1):
		dp[1][i][0] = dp[1][i][1] = 1
	for k in range(2, K + 1):
		for n in range(N, 0, -1):
			ans = 2
			if n < N:
				ans += dp[k][n + 1][0] - 1
			if n > 1:
				ans += dp[k - 1][n - 1][1] - 1
			dp[k][n][0] = ans % mod
		for n in range(1, N + 1):
			ans = 2
			if n < N:
				ans += dp[k - 1][n + 1][0] - 1
			if n > 1:
				ans += dp[k][n - 1][1] - 1
			dp[k][n][1] = ans % mod
	print(dp[K][1][0])


import collections
import math
from functools import lru_cache
from typing import OrderedDict
import sys

def process(tc, N, K):
	MOD = 10 ** 9 + 7
	dp = [[0 if k != 1 and n != 0 else 1 for n in range(N + 1)] for k in range(K + 1)]
	for k in range(2, K + 1):
		for n in range(1, N + 1):
			dp[k][n] = (dp[k][n - 1] + dp[k - 1][N - n]) % MOD
	print(dp[K][N], flush=True)
tcs = int(input())
for tc in range(tcs):
	(N, K) = list(map(int, input().split()))
	process(tc + 1, N, K)


import time
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	if k == 1:
		print('1')
	else:
		m = 1000000007
		s = 1 + n
		k = k - 1
		l = [1 for i in range(n - 1)]
		a = 0
		while k > 1:
			if k % 2 == 0:
				for i in range(n - 1):
					if i == 0:
						a = l[i]
						l[i] = a
						s = (s % m + a % m) % m
					else:
						a = (a % m + l[i] % m) % m
						l[i] = a
						s = (s % m + a % m) % m
			else:
				for i in range(-1, -n, -1):
					if i == -1:
						a = l[i]
						l[i] = a
						s = (s % m + a % m) % m
					else:
						a = (a % m + l[i] % m) % m
						l[i] = a
						s = (s % m + a % m) % m
			k -= 1
		print(s % m)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, K):
	MOD = 10 ** 9 + 7
	cost = [[1 for i in range(K + 1)] for j in range(N + 1)]
	for k in range(2, K + 1):
		pref = [0]
		for n in range(N + 1):
			pref.append(pref[-1] + cost[n][k - 1])
		for n in range(N + 1):
			ans = (pref[N] - pref[N - n] + 1) % MOD
			cost[n][k] = ans % MOD
	return cost[N][K]
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N, K) = [int(x) for x in input().split()]
	ans = solve(N, K)
	print(ans)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
from itertools import accumulate as ac
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	(n, k) = inp()
	if k == 1:
		ans = 1
	elif n == 1:
		ans = 2
	else:
		ans = 2
		cur = [1 for i in range(n - 1)]
		k -= 1
		for i in range(k):
			ans += sum(cur)
			ans %= mod
			if i & 1 == 0:
				p = 0
				for j in range(len(cur)):
					p += cur[j]
					cur[j] = p
					cur[j] %= mod
					p %= mod
			else:
				p = 0
				for j in range(len(cur) - 1, -1, -1):
					p += cur[j]
					cur[j] = p
					cur[j] %= mod
					p %= mod
	print(ans)


for u in range(int(input())):
	(n, k) = map(int, input().split())
	x = [1] * n
	ans = 1
	mod = 10 ** 9 + 7
	if k == 1:
		print(1)
	elif n == 1:
		print(2)
	else:
		k -= 2
		ans += n
		x = [1] * (n - 1)
		while k > 0:
			s = 0
			if k % 2 == 0:
				x[0] = x[0] % mod
				s += x[0] % mod
				for i in range(1, n - 1):
					x[i] = (x[i] + x[i - 1]) % mod
					s += x[i] % mod
			else:
				x[n - 2] = x[n - 2] % mod
				s += x[n - 2] % mod
				for i in range(n - 3, -1, -1):
					x[i] = (x[i] + x[i + 1]) % mod
					s += x[i] % mod
			ans += s % mod
			k -= 1
		print(ans % mod)


from collections import Counter
import string
import math
import bisect
import sys
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
mod = 10 ** 9 + 7
testcases = vary(1)
for _ in range(testcases):
	(n, k) = vary(2)
	dp = [[0 for i in range(n + 1)] for j in range(k)]
	ans = 0
	if 1:
		for i in range(1, k):
			for j in range(1, n + 1):
				dp[i][j] = (dp[i][j - 1] + dp[i - 1][n - j] + 1) % mod
	print((dp[-1][-1] + 1) % mod)