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

Solutions:
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)


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)


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 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 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()


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()


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])


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))


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 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()


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


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)


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])


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)