You are given a pyramid of the following form with an infinite number of rows:
1 
2\ 3
4\ 5\  6
7\ 8\ 9\ 10
...........

From a cell, you can move to either the bottom-left cell or the bottom-right cell directly in contact with the current one (For example, you can make the following moves: 1 \rightarrow 2, 1 \rightarrow 3, 6 \rightarrow 9, 6 \rightarrow 10, while you cannot make moves 2\to 6 or 2\rightarrow 7).

You are given a starting cell s and an ending cell e. Starting at cell s, find the number of ways to reach cell e. This number can be large, so print the answer modulo 10^{9} + 7.

Two ways are said to be different if there exists at least one cell which was visited in one of the ways but not the other one.

------ Input Format ------ 

- The first line of input contains a single integer T, the number of test cases. The description of T test cases follows.
- The first and only line of each test case contains two space-separated integers s and e, denoting the starting and the ending cell respectively.

------ Output Format ------ 

For each test case, output a single line containing one integer: the number of ways to go from s to e modulo 10^{9} + 7.

------ Constraints ------ 

$1 ≤ T ≤ 1000$
$1 ≤ s, e≤ 10^{9}$

------ subtasks ------ 

Subtask 1(100 points): Original constraints

----- Sample Input 1 ------ 
3
2 7
1 5
5 3
----- Sample Output 1 ------ 
1
2
0
----- explanation 1 ------ 
In the first test case, there exists only $1$ way to move from $2$ to $7$, which is: 
- $2 \rightarrow 4 \rightarrow 7$

In the second test case, there exist $2$ ways to move from $1$ to $5$, which are: 
- $1 \rightarrow 2 \rightarrow 5$
- $1 \rightarrow 3 \rightarrow 5$

In the third test case, it is not possible to move from $5$ to $3$.

Difficulty: HARD

Solutions:
import math
MOD7 = pow(10, 9) + 7
MAXF = pow(10, 5)
my_list = [0] * (MAXF + 1)

def last(l):
	return (l + 1) * l / 2

def get_level_and_index(n):
	idx = -1
	line = -1
	if n == 1:
		return (1, 1)
	left = 2
	right = 1 + math.floor(math.sqrt(2 * n))
	while left <= right:
		line = int((left + right) / 2)
		if last(line) >= n and last(line - 1) < n:
			break
		elif last(line > n):
			right = l - 1
		else:
			left = line + 1
	idx = int(n - line * (line - 1) / 2)
	return (line, idx)

def pow_mod(x, y, p):
	x = x % p
	if x == 0:
		return 0
	res = 1
	while y > 0:
		if y & 1:
			res = res * x
			res = res % p
			y = y - 1
		x = x * x % p
		y = int(y / 2)
	return res

def inv(x, p):
	return pow_mod(x, p - 2, p)

def lci(line, i, p=MOD7):
	x = my_list[line] * inv(my_list[i], p) % p
	y = inv(my_list[line - i], p)
	return x * y % p
my_list[0] = 1
my_list[1] = 1
for i in range(2, MAXF):
	my_list[i] = my_list[i - 1] * i % MOD7
T = int(input())
for _ in range(T):
	(s, e) = map(int, input().split(' '))
	(start_l, start_i) = get_level_and_index(s)
	(end_l, end_i) = get_level_and_index(e)
	line = end_l - start_l
	i = end_i - start_i
	ans = -1
	if line <= 0 or i < 0 or i > line:
		ans = 0
	else:
		ans = lci(line, i)
	print(ans)


from math import ceil, sqrt
display_modulo = 10 ** 9 + 7
max_factor = 10 ** 5
factors = [None] * (max_factor + 1)

def power_modulo(a, b, pow):
	a %= pow
	if a == 0:
		return 0
	prod = 1
	while b > 0:
		if b % 2 == 1:
			prod *= a
			prod %= pow
			b -= 1
		a *= a
		a %= pow
		b //= 2
	return prod

def binom(n, k, p):
	return factors[n] * inv(factors[k], p) % p * inv(factors[n - k], p) % p

def inv(a, p):
	return power_modulo(a, p - 2, p)

def get_last_node(level):
	return (level + 1) * level // 2

def get_level_index_tuple(n):
	i = -1000
	l = -1000
	if n == 1:
		return (1, 1)
	finish = 1 + ceil(sqrt(n * 2))
	begin = 2
	while begin <= finish:
		l = (begin + finish) // 2
		last = get_last_node(l)
		if last >= n and get_last_node(l - 1) < n:
			break
		elif last > n:
			finish = l - 1
		else:
			begin = l + 1
	i = n - l * (l - 1) // 2
	return (l, i)
factors[0] = 1
factors[1] = 1
for i in range(2, max_factor + 1):
	factors[i] = factors[i - 1] * i % display_modulo
for _ in range(int(input())):
	(s, e) = map(int, input().split())
	t1 = get_level_index_tuple(s)
	t2 = get_level_index_tuple(e)
	res = -1000
	i_difference = t2[1] - t1[1]
	l_difference = t2[0] - t1[0]
	if l_difference <= 0 or i_difference < 0 or i_difference > l_difference:
		res = 0
	else:
		res = binom(l_difference, i_difference, display_modulo)
	print(res)


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

def getcoord(num):
	y = int((2 * num + 0.25) ** 0.5 + 0.5)
	x = int(num - y * (y - 1) / 2)
	if x == 0:
		y -= 1
		x = y
	return (x, y)
T = int(input())
for i in range(T):
	(s, e) = map(int, input().split())
	E = getcoord(e)
	S = getcoord(s)
	n = E[1] - S[1]
	r = E[0] - S[0]
	if n < 1 or r < 0 or n < r:
		print(0)
	else:
		print(ncr(n, r, 10 ** 9 + 7))


import sys
from math import floor, sqrt
T = int(input())
prime = 10 ** 9 + 7
MAX_LINE = 10 ** 5 + 5
factorials = [None] * MAX_LINE

def modulo_power(a, b):
	res = 1
	while b > 0:
		res = res * a % prime
		b -= 1
	return res

def power(x, y, m=prime):
	x %= m
	res = 1
	while y > 0:
		if y % 2 == 1:
			res = res * x % m
		y = y // 2
		x = x * x % m
	return res

def power_modulo(a, b, pow=prime):
	a %= pow
	if a == 0:
		return 0
	prod = 1
	while b > 0:
		if b % 2 == 1:
			prod *= a
			prod %= pow
			b -= 1
		a *= a
		a %= pow
		b //= 2
	return prod
factorials[0] = 1
for i in range(1, MAX_LINE):
	factorials[i] = factorials[i - 1] * i % prime

def modulo_fact(n):
	return factorials[n]

def modulo_inverse_fact(n):
	a = modulo_fact(n)
	return power(a, prime - 2) % prime

def comb_formula(n, p):
	if n < 0 or p < 0 or n - p < 0:
		return 0
	else:
		return modulo_fact(n) * modulo_inverse_fact(p) % prime * modulo_inverse_fact(n - p) % prime

def testcase():

	def series_sum(n):
		return n * (n + 1) / 2

	def get_line_no(n):
		close_line = floor(sqrt(2 * n))
		line_end = series_sum(close_line)
		if line_end < n:
			close_line += 1
			index = n - line_end
		else:
			index = close_line - line_end + n
		return (close_line, int(index))
	(s, e) = map(int, input().split())
	(s_line, s_ind) = get_line_no(s)
	(e_line, e_ind) = get_line_no(e)
	print(int(comb_formula(e_line - s_line, e_ind - s_ind)))
for _ in range(T):
	testcase()


import sys
input = sys.stdin.readline
import math

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

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

def level(n):
	n = n * 2
	ans = 4 * n + 1
	d = math.ceil(math.sqrt(ans) - 1)
	if d % 2 != 0:
		d += 1
	level = d // 2
	return int(level)

def LR(n):
	level = 1
	while True:
		sm = level * (level + 1) // 2
		if sm >= n:
			rank = level - abs(sm - n)
			return (level, rank)
		level += 1
for _ in range(int(input())):
	lst = list(map(int, input().split()))
	(s, e) = (lst[0], lst[1])
	if s == e:
		print(0)
		continue
	ls = level(s)
	le = level(e)
	sms = int(ls * (ls + 1) // 2)
	sme = int(le * (le + 1) // 2)
	rs = ls - abs(sms - s)
	re = le - abs(sme - e)
	ld = le - ls
	if ld >= 0:
		if (re - rs < 0 or ld < re - rs) != True:
			ans = ncr(ld, re - rs, 10 ** 9 + 7)
			print(ans)
		else:
			print(0)
	else:
		print(0)


import math
max_no = int(100000.0)
mod_7 = int(1000000000.0 + 7)
factorial = [None] * (max_no + 1)
factorial[0] = 1
factorial[1] = 1
for i in range(2, max_no + 1):
	factorial[i] = factorial[i - 1] * i % mod_7

def last_elem(lvl):
	return (lvl + 1) * lvl // 2

def powmod(a, b, p):
	a %= p
	if a == 0:
		return 0
	product = 1
	while b > 0:
		if b % 2 == 1:
			product *= a
			product %= p
			b -= 1
		a *= a
		a %= p
		b //= 2
	return product

def inv(a, p):
	return powmod(a, p - 2, p)

def nCk(n, k, p):
	return factorial[n] * inv(factorial[k], p) % p * inv(factorial[n - k], p) % p

def get_level_index(n):
	lvl = -1
	idx = -1
	if n == 1:
		return [(1, 1)]
	start = 2
	end = 1 + math.ceil(math.sqrt(n * 2))
	while start <= end:
		lvl = (start + end) // 2
		if last_elem(lvl) >= n and last_elem(lvl - 1) < n:
			break
		elif last_elem(lvl) > n:
			end = lvl - 1
		else:
			start = lvl + 1
	idx = n - lvl * (lvl - 1) // 2
	return [(lvl, idx)]
t = int(input())
for _ in range(t):
	(s, e) = map(int, input().split())
	result_1 = []
	result_2 = []
	result_1 = get_level_index(s)
	result_2 = get_level_index(e)
	s1v1 = result_1[0][0]
	sidx = result_1[0][1]
	e1v1 = result_2[0][0]
	eidx = result_2[0][1]
	L = e1v1 - s1v1
	K = eidx - sidx
	ans = -1
	if L <= 0 or K < 0 or K > L:
		ans = 0
	else:
		ans = nCk(L, K, mod_7)
	print(ans)


import math

class solution:

	def __init__(self):
		self.mod = 1000000007
		self.fact = []
		self.fact.append(1)
		self.fact.append(1)
		for i in range(2, 100001):
			self.fact.append(self.fact[-1] * i % self.mod)

	def powMod(self, p, base, Pow):
		base = base % p
		if base == 0:
			return 0
		product = 1
		while Pow > 0:
			if Pow % 2 == 1:
				Pow -= 1
				product = product * base
				product = product % p
			Pow = Pow // 2
			base = base * base
			base = base % p
		return product

	def lastElem(self, lvl):
		return (lvl + 1) * lvl // 2

	def getLvlIdx(self, n):
		lvl = -1
		idx = -1
		if n == 1:
			return (1, 1)
		st = 2
		end = 1 + math.ceil(math.sqrt(2 * n))
		while st <= end:
			lvl = (st + end) // 2
			if self.lastElem(lvl) >= n and self.lastElem(lvl - 1) < n:
				break
			elif self.lastElem(lvl) > n:
				end = lvl - 1
			else:
				st = lvl + 1
		idx = n - lvl * (lvl - 1) // 2
		return (lvl, idx)

	def inv(self, a, p):
		return self.powMod(p, a, p - 2)

	def nCk(self, n, k, p):
		return self.fact[n] * self.inv(self.fact[k], p) % p * self.inv(self.fact[n - k], p) % p
t = int(input())
solver = solution()
for tests in range(t):
	l = list(map(int, input().split()))
	s = l[0]
	res1 = solver.getLvlIdx(s)
	sidx = res1[1]
	slvl = res1[0]
	e = l[1]
	res2 = solver.getLvlIdx(e)
	elvl = res2[0]
	eidx = res2[1]
	Ldiff = elvl - slvl
	Idiff = eidx - sidx
	res = 0
	if Ldiff > 0 and Idiff >= 0 and (Idiff <= Ldiff):
		res = solver.nCk(Ldiff, Idiff, 1000000007)
	print(res)


import math
mod7 = 1000000007
MAXF = 100000

def last_elem(lvl):
	return (lvl + 1) * lvl // 2

def powmod(a, b, p):
	a %= p
	if a == 0:
		return 0
	product = 1
	while b > 0:
		if b & 1:
			product *= a
			product %= p
			b -= 1
		a *= a
		a %= p
		b //= 2
	return product

def inv(a, p):
	return powmod(a, p - 2, p)

def nck(n, k, p):
	return arr[n] * inv(arr[k], p) % p * inv(arr[n - k], p) % p

def get_lvl_idx(n):
	lvl = -1
	idx = -1
	if n == 1:
		return [1, 1]
	st = 2
	end = math.ceil(math.sqrt(2 * n))
	while st <= end:
		lvl = (st + end) // 2
		if last_elem(lvl) >= n and last_elem(lvl - 1) < n:
			break
		elif last_elem(lvl) > n:
			end = lvl - 1
		else:
			st = lvl + 1
	idx = n - lvl * (lvl - 1) // 2
	return [lvl, idx]
arr = [0 for i in range(MAXF)]
arr[0] = 1
arr[1] = 1
for i in range(2, MAXF):
	arr[i] = arr[i - 1] * i % mod7
t = int(input())
for _ in range(t):
	(s, e) = map(int, input().split())
	res1 = get_lvl_idx(s)
	res2 = get_lvl_idx(e)
	x1 = res1[0]
	x2 = res1[1]
	x3 = res2[0]
	x4 = res2[1]
	L = x3 - x1
	K = x4 - x2
	ans = -1
	if L <= 0 or K < 0 or K > L:
		ans = 0
	else:
		ans = nck(L, K, mod7)
	print(ans)


from math import sqrt, ceil
MOD = 10 ** 9 + 7
MAX = 10 ** 5
factors = [None] * (MAX + 1)

def get_last_elem_in_lvl(level_index):
	return (level_index + 1) * level_index // 2

def powerer_mod(num1, num2, power):
	num1 %= power
	if 0 == num1:
		return 0
	res = 1
	while num2 > 0:
		if num2 % 2 == 1:
			res *= num1
			res %= power
			num2 -= 1
		num1 *= num1
		num1 %= power
		num2 //= 2
	return res

def inv(num, power):
	return powerer_mod(num, power - 2, power)

def binom_nCk(n, k, p):
	return factors[n] * inv(factors[k], p) % p * inv(factors[n - k], p) % p

def get_number_level_and_index_tuple(number):
	if 1 == number:
		return (1, 1)
	start = 2
	end = 1 + ceil(sqrt(number * 2))
	while start <= end:
		level = (start + end) // 2
		last = get_last_elem_in_lvl(level)
		if last >= number and get_last_elem_in_lvl(level - 1) < number:
			break
		elif last > number:
			end = level - 1
		else:
			start = level + 1
	index = number - level * (level - 1) // 2
	return (level, index)
factors[0] = 1
factors[1] = 1
for i in range(2, MAX + 1):
	factors[i] = factors[i - 1] * i % MOD
T = int(input())
for _ in range(T):
	(S, E) = map(int, input().split())
	S_tuple = get_number_level_and_index_tuple(S)
	E_tuple = get_number_level_and_index_tuple(E)
	delta_l = E_tuple[0] - S_tuple[0]
	delta_i = E_tuple[1] - S_tuple[1]
	if delta_l <= 0 or delta_i < 0 or delta_i > delta_l:
		res = 0
	else:
		res = binom_nCk(delta_l, delta_i, MOD)
	print(res)


from math import ceil, sqrt
print_mod = 10 ** 9 + 7
max_factor = 10 ** 5
factors = [None] * (max_factor + 1)

def get_last_item(level_index):
	return (level_index + 1) * level_index // 2

def power_and_mod(a, b, pow):
	a %= pow
	if a == 0:
		return 0
	prod = 1
	while b > 0:
		if b % 2 == 1:
			prod *= a
			prod %= pow
			b -= 1
		a *= a
		a %= pow
		b //= 2
	return prod

def inv(a, p):
	return power_and_mod(a, p - 2, p)

def binom(n, k, p):
	return factors[n] * inv(factors[k], p) % p * inv(factors[n - k], p) % p

def get_number_level_and_index_tuple(number):
	level = -1000
	index = -1000
	if number == 1:
		return (1, 1)
	start = 2
	end = 1 + ceil(sqrt(number * 2))
	while start <= end:
		level = (start + end) // 2
		last = get_last_item(level)
		if last >= number and get_last_item(level - 1) < number:
			break
		elif last > number:
			end = level - 1
		else:
			start = level + 1
	index = number - level * (level - 1) // 2
	return (level, index)
factors[0] = 1
factors[1] = 1
for i in range(2, max_factor + 1):
	factors[i] = factors[i - 1] * i % print_mod
t = int(input())
for _ in range(t):
	(s, e) = map(int, input().split())
	first_tuple = get_number_level_and_index_tuple(s)
	second_tuple = get_number_level_and_index_tuple(e)
	levels_diff = second_tuple[0] - first_tuple[0]
	index_diff = second_tuple[1] - first_tuple[1]
	result = -1000
	if levels_diff <= 0 or index_diff < 0 or index_diff > levels_diff:
		result = 0
	else:
		result = binom(levels_diff, index_diff, print_mod)
	print(result)


import math
modulu7 = pow(10, 9) + 7
maximum = pow(10, 5)
my_list = [0] * (maximum + 1)

def getLevelAndIndex(n):
	if n == 1:
		return (1, 1)
	ind = -1
	line = -1
	left = 2
	right = 1 + math.floor(math.sqrt(2 * n))
	while left <= right:
		line = int((left + right) / 2)
		if last(line) >= n and last(line - 1) < n:
			break
		elif last(line > n):
			right = l - 1
		else:
			left = line + 1
	ind = int(n - line * (line - 1) / 2)
	return (line, ind)

def moduluPower(base, y, p):
	if base == 0:
		return 0
	base = base % p
	res = 1
	while y > 0:
		if y & 1:
			res = res * base
			res = res % p
			y -= 1
		base = base * base % p
		y = int(y / 2)
	return res

def last(l):
	return (l + 1) * l / 2

def inv(x, p):
	if x > 0:
		return moduluPower(x, p - 2, p)
	else:
		return moduluPower(x, p - 2, p)

def lci(line, i, p=modulu7):
	xValue = inv(my_list[i], p) * my_list[line] % p
	yValue = inv(my_list[line - i], p)
	XMulY = xValue * yValue
	return XMulY % p
my_list[1] = 1
my_list[0] = 1
for i in range(2, maximum):
	my_list[i] = i * my_list[i - 1] % modulu7
T = int(input())
for _ in range(T):
	(s, e) = map(int, input().split(' '))
	(startL, startI) = getLevelAndIndex(s)
	(endL, endI) = getLevelAndIndex(e)
	line = endL - startL
	i = endI - startI
	ans = -1
	if line < 1 or i < 0 or i > line:
		ans = 0
	else:
		ans = lci(line, i)
	print(ans)


import math
MAXF = pow(10, 5)
fact = [0] * (MAXF + 1)
MOD7 = pow(10, 9) + 7

def inv(a, p):
	return pow_mod(a, p - 2, p)

def levelCindex(level, index, p=MOD7):
	a = fact[level] * inv(fact[index], p)
	a = a % p
	b = inv(fact[level - index], p)
	return a * b % p

def get_level_index(n):
	if n == 1:
		return (1, 1)
	level = -1
	index = -1
	start = 2
	end = 1 + math.floor(math.sqrt(2 * n))
	while start <= end:
		level = int((start + end) / 2)
		if last_element(level) > n - 1 and last_element(level - 1) < n:
			break
		elif last_element(level > n):
			end = level - 1
		else:
			start = level + 1
	index = int(n - level * (level - 1) / 2)
	return (level, index)

def pow_mod(a, b, p):
	a = a % p
	if a == 0:
		return 0
	product = 1
	while b > 0:
		if b & 1:
			product = product * a
			product = product % p
			b = b - 1
		a = a * a
		a = a % p
		b = int(b / 2)
	return product

def last_element(level):
	res = level * (level + 1)
	return res / 2
fact[0] = 1
fact[1] = 1
for i in range(2, MAXF):
	fact[i] = fact[i - 1] * i % MOD7
T = int(input())
for _ in range(T):
	(s, e) = map(int, input().split(' '))
	(start_level, start_index) = get_level_index(s)
	(end_level, end_index) = get_level_index(e)
	level = end_level - start_level
	index = end_index - start_index
	ans = -1
	if level <= 0 or index < 0 or index > level:
		ans = 0
	else:
		ans = levelCindex(level, index)
	print(ans)


from math import sqrt

def level(x):
	le = lambda i: i * (i + 1) // 2
	if x == 1:
		return (1, 1)
	else:
		st = 2
		end = int(sqrt(2 * x)) + 1
		while st <= end:
			mid = (st + end) // 2
			t1 = le(mid)
			t2 = le(mid - 1)
			if x <= t1 and t2 < x:
				break
			elif t1 < x:
				st = mid + 1
			else:
				end = mid - 1
		return (mid, x - le(mid - 1))

def factorial(y):
	if y < 2:
		return y
	else:
		f = [0 for i in range(y + 1)]
		f[0] = 1
		f[1] = 1
		i = 2
		while i < y + 1:
			f[i] = f[i - 1] * i % (10 ** 9 + 7)
			i += 1
		return f[y]
T = int(input())
for tc in range(T):
	(s, e) = map(int, input().split())
	(s1, s2) = level(s)
	(e1, e2) = level(e)
	a = e1 - s1
	b = e2 - s2
	if a <= 0 or b < 0 or b > a:
		print(0)
	else:
		z = 10 ** 9 + 7
		nm = 1
		dn = 1
		for i in range(b):
			nm = nm * (a - i) % z
			dn = dn * (i + 1) % z
		print(nm * pow(dn, z - 2, z) % z)


t = int(input())
fact = [0] * (10 ** 5 + 7)
fact[0] = fact[1] = 1
for i in range(2, 10 ** 5 + 7):
	fact[i] = i * fact[i - 1] % (10 ** 9 + 7)

def get_level_indx(s):
	n = int((1 + pow(1 + 8 * (s - 1), 0.5)) / 2)
	n_start = n * (n - 1) // 2 + 1
	s_indx = s - n_start
	return (n, s_indx + 1)

def inv(x, y):
	return pow(x, y - 2, y)

def solve(n, k, p=10 ** 9 + 7):
	return fact[n] * inv(fact[k], p) % p * inv(fact[n - k], p) % p
for _ in range(t):
	(s, e) = [int(x) for x in input().split()]
	(s_level, s_indx) = get_level_indx(s)
	(e_level, e_indx) = get_level_indx(e)
	level_diff = e_level - s_level
	indx_diff = e_indx - s_indx
	if level_diff <= 0 or indx_diff < 0 or indx_diff > level_diff:
		print(0)
	else:
		print(solve(level_diff, indx_diff))


import math

def modPow(a, x, p):
	res = 1
	while x > 0:
		if x % 2 != 0:
			res = res * a % p
		a = a * a % p
		x //= 2
	return res

def modInverse(a, p):
	return modPow(a, p - 2, p)

def modBinomial(n, k, p):
	numerator = 1
	for i in range(k):
		numerator = numerator * (n - i) % p
	denominator = 1
	for i in range(1, k + 1):
		denominator = denominator * i % p
	return numerator * modInverse(denominator, p) % p

def binarySearch(num):
	if num == 1:
		return 1
	left = 2
	right = 1 + math.ceil(math.sqrt(2 * num))
	middle = -1
	while left < right:
		middle = (right + left) // 2
		lastElem = middle * (middle + 1) // 2
		prevLast = middle * (middle - 1) // 2
		if prevLast < num <= lastElem:
			break
		elif num < lastElem:
			right = middle
		else:
			left = middle
	return middle

def findLoc(num):
	level = binarySearch(num)
	ind = num - level * (level - 1) // 2
	res = (level, ind)
	return res

def findNumOfPaths(s, e):
	dataS = findLoc(s)
	dataE = findLoc(e)
	levels = dataE[0] - dataS[0]
	indices = dataE[1] - dataS[1]
	p = 10 ** 9 + 7
	if levels <= 0 or indices < 0 or indices > levels:
		return 0
	else:
		return modBinomial(levels, indices, p)
T = int(input())
for _ in range(T):
	(s, e) = map(int, input().split())
	print(findNumOfPaths(s, e))


import math
MOD = 1000000007
memo_table = {}

def get_level(k):
	return math.ceil((math.sqrt(8 * k + 1) - 1) / 2)

def check_path(m, lsv, lev):
	if m >= lsv and m <= lev:
		return True
	else:
		return False

def get_end_level_interval(n, sl, el):
	diff = el - sl
	lsv = n + diff * (sl + el - 1) // 2
	lev = n + diff * (sl + 1 + el) // 2
	return (lsv, lev)

def get_paths(h, k):
	if (h, k) in memo_table:
		return memo_table[h, k]
	elif (k, h) in memo_table:
		return memo_table[k, h]
	else:
		num = den = 1
		for i in range(k - 1):
			num = num * (h + k - 2 - i) % MOD
			den = den * (i + 1) % MOD
		res = num * pow(den, MOD - 2, MOD) % MOD
		memo_table[h, k] = res
		return res
t = int(input())
while t:
	(n, m) = tuple(map(int, input().strip().split()))[:2]
	if n >= m:
		print(0)
		t -= 1
		continue
	N = get_level(n)
	M = get_level(m)
	if M == N:
		print(0)
		t -= 1
		continue
	(lsv, lev) = get_end_level_interval(n, N, M)
	if check_path(m, lsv, lev):
		s1 = M - N - (m - lsv) + 1
		s2 = m - lsv + 1
		res = get_paths(s1, s2)
		print(res)
		t -= 1
		continue
	else:
		print(0)
		t -= 1
		continue


def level(i):
	st = 1
	en = 10000000
	while st <= en:
		mid = (st + en) // 2
		if mid * (mid + 1) // 2 > i:
			en = mid - 1
		elif mid * (mid + 1) // 2 < i:
			st = mid + 1
		else:
			return mid
	return st

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
MOD = 10 ** 9 + 7
t = int(input())
while t:
	t -= 1
	(s, e) = map(int, input().split(' '))
	if s > e:
		print(0)
		continue
	(ns, ne) = (level(s) - 1, level(e) - 1)
	(rs, re) = (s - ns * (ns + 1) // 2 - 1, e - ne * (ne + 1) // 2 - 1)
	if ne <= ns or re < rs:
		print(0)
		continue
	print(ncr(ne - ns, re - rs, MOD))


import math
mod7 = 10 ** 9 + 7
maxf = 10 ** 5
fact = [0] * (maxf + 1)
fact[0] = fact[1] = 1
for i in range(2, maxf + 1):
	fact[i] = fact[i - 1] * i % mod7

def powmod(a, b, p):
	a %= p
	if a == 0:
		return 0
	to_ret = 1
	while b > 0:
		if b % 2 == 1:
			to_ret *= a
			to_ret %= p
			b -= 1
		a *= a
		a %= p
		b = int(b / 2)
	return to_ret

def inv(a, p):
	return powmod(a, p - 2, p)

def nCk(n, k, p):
	return fact[n] * inv(fact[k], p) % p * inv(fact[n - k], p) % p

def last_item(lvl):
	return int((lvl + 1) * lvl / 2)

def lvl_idx(n: int):
	lvl: int = -1
	idx: int = -1
	if n == 1:
		return (1, 1)
	st: int = 2
	end: int = 1 + int(math.ceil(math.sqrt(2 * n)))
	while st <= end:
		lvl = int((st + end) / 2)
		if last_item(lvl) >= n > last_item(lvl - 1):
			break
		elif last_item(lvl) > n:
			end = lvl - 1
		else:
			st = lvl + 1
	idx = n - int(lvl * (lvl - 1) / 2)
	return (lvl, idx)
try:
	for t in range(int(input())):
		the_input = input().split()
		s = int(the_input[0])
		e = int(the_input[1])
		res1 = lvl_idx(s)
		res2 = lvl_idx(e)
		L = res2[0] - res1[0]
		K = res2[1] - res1[1]
		res = -1
		if L <= 0 or K < 0 or K > L:
			res = 0
		else:
			res = nCk(L, K, mod7)
		print(res)
except EOFError as e:
	pass


import math
from fractions import Fraction

def factorial():
	fact[0] = 1
	fact[1] = 1
	for i in range(2, 100001):
		fact[i] = fact[i - 1] * i % 1000000007

def inverse(n):
	v = 1000000005
	p = 1000000007
	n = n % p
	if n == 0:
		return 0
	val = 1
	while v > 0:
		if v % 2 == 1:
			val = val * n
			val = val % p
			v -= 1
		n = n * n
		n = n % p
		v = v // 2
	return val

def ncr(n, r):
	fn = fact[n]
	fr = fact[r]
	fnr = fact[n - r]
	val = fnr * fr
	ls = str(Fraction(fn, val)).split('/')
	if len(ls) == 1:
		numr = int(ls[0])
		val = numr % 1000000007
	else:
		numr = int(ls[0])
		denmr = int(ls[1])
		denmr = inverse(denmr)
		val = numr * denmr % 1000000007
	return val

def pos(n):
	if n == 1:
		return (1, 1)
	l = 1
	r = int(math.sqrt(2 * n)) + 2
	while l <= r:
		m = (l + r) // 2
		lm = m * (m + 1) // 2
		lm1 = (m - 1) * m // 2
		if lm >= n and lm1 < n:
			break
		elif lm < n:
			l = m + 1
		else:
			r = m - 1
	pos = n - m * (m - 1) // 2
	return (m, pos)
fact = [1] * 100001
factorial()
t = int(input())
for i in range(t):
	(s, e) = map(int, input().split())
	(sl, spos) = pos(s)
	(el, epos) = pos(e)
	dl = el - sl
	dpos = epos - spos
	if dl > 0 and (dpos >= 0 and dpos <= dl):
		print(ncr(dl, dpos))
	else:
		print(0)


import math

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

def coordinates(a):
	D = math.sqrt(8 * a + 1)
	n = (D - 1) / 2
	if n.is_integer():
		y = int(n)
	else:
		y = math.ceil(n)
	x = 2 * a - y * y - 1
	coordinate = (x, y)
	return coordinate

def possible_ways(s, e):
	x1 = coordinates(s)[0]
	x2 = coordinates(e)[0]
	y1 = coordinates(s)[1]
	y2 = coordinates(e)[1]
	answer = 0
	if s == e:
		answer = 1
	elif y2 - y1 < abs(x2 - x1):
		answer = 0
	else:
		answer = ncr(int(y2 - y1), int(int(y2 - y1 + x2 - x1) / 2), 1000000007)
	return answer
T = int(input())
for i in range(T):
	list = [int(x) for x in input().split()]
	s = list[0]
	e = list[1]
	print(possible_ways(s, e))


import math
mod = int(1000000000.0 + 7)
fact = {}
fact[0] = 1
for i in range(1, 1000001):
	fact[i] = int(fact[i - 1] * i % mod)

def find_lvl_ind(v):
	D = math.ceil(math.sqrt(1 + 8 * v))
	if D % 2 == 0:
		D = D + 1
	lvl = (D - 1) / 2
	while True:
		l = (lvl - 1) * lvl / 2
		m = (lvl + 1) * lvl / 2
		if v <= m and v > l:
			break
		elif v > m:
			lvl = lvl + 1
		else:
			lvl = lvl - 1
	last_lvl_max = (lvl - 1) * lvl / 2
	index = v - last_lvl_max
	return (lvl, index - 1)

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

def modInverse(a, p):
	return power(a, p - 2, p)

def nCrModp(n, r, p):
	return fact[n] * modInverse(fact[r], p) % p * modInverse(fact[n - r], p) % p
for _ in range(int(input())):
	(s, e) = map(int, input().split())
	(s_lvl, s_index) = find_lvl_ind(s)
	(e_lvl, e_index) = find_lvl_ind(e)
	L = e_lvl - s_lvl
	I = e_index - s_index
	p = 1
	if I > L or I < 0 or L <= 0:
		p = 0
	else:
		p = nCrModp(int(L), int(I), mod)
	print(int(p))


import math
mod7 = 10 ** 9 + 7
maxf = 10 ** 5
fact = [0] * (maxf + 1)

def power_mod(a, b, p):
	a %= p
	if a == 0:
		return 0
	product = 1
	while b > 0:
		if b % 2 == 1:
			product *= a
			product %= p
			b -= 1
		a *= a
		a %= p
		b = int(b / 2)
	return product

def inv(a, p):
	return power_mod(a, p - 2, p)

def number_of_routes(n, k, p):
	return fact[n] * inv(fact[k], p) % p * inv(fact[n - k], p) % p

def last_elem(level):
	return int((level + 1) * level / 2)

def level_and_index(n):
	level = -1
	index = -1
	if n == 1:
		return (1, 1)
	st = 2
	end = 1 + int(math.ceil(math.sqrt(2 * n)))
	while st <= end:
		level = int((st + end) / 2)
		if last_elem(level) >= n > last_elem(level - 1):
			break
		elif last_elem(level) > n:
			end = level - 1
		else:
			st = level + 1
	index = n - int(level * (level - 1) / 2)
	return (level, index)
fact[0] = fact[1] = 1
for i in range(2, maxf + 1):
	fact[i] = fact[i - 1] * i % mod7
times = int(input())
results = []
for i in range(times):
	inputs = input().split()
	s = int(inputs[0])
	e = int(inputs[1])
	(s_level, s_index) = level_and_index(s)
	(e_level, e_index) = level_and_index(e)
	level = e_level - s_level
	index = e_index - s_index
	if level <= 0 or index < 0 or index > level:
		result = 0
	else:
		result = number_of_routes(level, index, mod7)
	results.append(result)
for r in results:
	print(r)


import math
mod7 = 10 ** 9 + 7
maxf = 10 ** 5
fact = [0] * (maxf + 1)

def powmod(a, b, p):
	a %= p
	if a == 0:
		return 0
	product = 1
	while b > 0:
		if b % 2 == 1:
			product *= a
			product %= p
			b -= 1
		a *= a
		a %= p
		b = int(b / 2)
	return product

def inv(a, p):
	return powmod(a, p - 2, p)

def nCk(n, k, p):
	return fact[n] * inv(fact[k], p) % p * inv(fact[n - k], p) % p

def last_elem(lvl):
	return int((lvl + 1) * lvl / 2)

def lvl_idx(n: int):
	lvl: int = -1
	idx: int = -1
	if n == 1:
		return (1, 1)
	st: int = 2
	end: int = 1 + int(math.ceil(math.sqrt(2 * n)))
	while st <= end:
		lvl = int((st + end) / 2)
		if last_elem(lvl) >= n > last_elem(lvl - 1):
			break
		elif last_elem(lvl) > n:
			end = lvl - 1
		else:
			st = lvl + 1
	idx = n - int(lvl * (lvl - 1) / 2)
	return (lvl, idx)
fact[0] = fact[1] = 1
for i in range(2, maxf + 1):
	fact[i] = fact[i - 1] * i % mod7
t = int(input())
for _ in range(t):
	(s, e) = tuple((int(x) for x in input().split()))
	res1 = lvl_idx(s)
	res2 = lvl_idx(e)
	slv1 = res1[0]
	sidx = res1[1]
	elv1 = res2[0]
	eidx = res2[1]
	L = elv1 - slv1
	K = eidx - sidx
	_ans = -1
	if L <= 0 or K < 0 or K > L:
		_ans = 0
	else:
		_ans = nCk(L, K, mod7)
	print(_ans)


import math

def XtoRC(X):
	R = math.ceil((math.sqrt(8 * X + 1) - 1) / 2 - 1)
	C = 2 * (X - 1) - R * (R + 2)
	return (R, C)

def RCtoX(R, C):
	return (C + R * (R + 2)) // 2 + 1
MOD = 10 ** 9 + 7

def modpow(base, exp, mod):
	result = 1
	while exp:
		if exp & 1:
			result = result * base % mod
		base = base * base % mod
		exp >>= 1
	return result

def modinv(base, mod):
	return modpow(base, mod - 2, mod)
(FACT, FACTINV) = ([1] * 44750, [1] * 44750)
for k in range(1, 44750):
	FACT[k] = k * FACT[k - 1] % MOD
	FACTINV[k] = modinv(FACT[k], MOD)

def naive(RS, CS, RE, CE):
	if RS == RE and CS == CE:
		return 1
	if abs(CE - CS) > RE - RS:
		return 0
	if CE > CS:
		CE = CS * 2 - CE
	(RS, CS, RE, CE) = (0, 0, RE - RS, CE - CS)
	return FACT[RE] * FACTINV[(RE + CE) // 2] * FACTINV[(RE - CE) // 2] % MOD

def main(S, E):
	(RC_S, RC_E) = (XtoRC(S), XtoRC(E))
	return naive(RC_S[0], RC_S[1], RC_E[0], RC_E[1])
T = int(input().strip())
for _ in range(T):
	(S, E) = [int(x) for x in input().strip().split()[:2]]
	print(main(S, E))


def find_row_col(num):
	(low, high) = (1, 50000)
	row = -1
	while low <= high:
		mid = (low + high) // 2
		val = mid * (mid + 1) // 2
		if num > val:
			low = mid + 1
		else:
			row = mid
			high = mid - 1
	k = num - row * (row - 1) // 2
	return (k, row - k + 1)
P = int(1000000000.0 + 7)

def nCr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % P
		den = den * (i + 1) % P
	return num * pow(den, P - 2, P) % P
for _ in range(int(input())):
	(s, e) = map(int, input().strip().split())
	((row_s, col_s), (row_e, col_e)) = (find_row_col(s), find_row_col(e))
	if row_e < row_s or col_e < col_s:
		print(0)
	elif row_e == row_s and col_e == col_s:
		print(1)
	else:
		(m, n) = (row_e - row_s, col_e - col_s)
		print(nCr(m + n, min(m, n)))


m = pow(10, 9) + 7
fac_m = [0 for c in range(50001)]
fac_m[0] = 1
for i in range(1, 50001):
	fac_m[i] = fac_m[i - 1] * i % m
inv_fac_m = [0 for d in range(50001)]
inv_fac_m[50000] = pow(fac_m[-1], m - 2, m)
for j in range(49999, -1, -1):
	inv_fac_m[j] = inv_fac_m[j + 1] * (j + 1) % m
import math
for i in range(int(input())):
	(s, e) = map(int, input().split())

	def row(x):
		res = (-1 + math.sqrt(1 + 8 * x)) / 2
		return math.ceil(res)
	s_row = row(s)
	e_row = row(e)
	n = e_row - s_row
	a = s + (e_row - s_row) * (e_row + s_row - 1) // 2
	b = s + (e_row - s_row) * (e_row + s_row + 1) // 2
	if n <= 0:
		print(0)
	elif e > b or e < a:
		print(0)
	else:
		k = e - a
		print(fac_m[n] * inv_fac_m[k] * inv_fac_m[n - k] % m)


import bisect as bi
M = 10 ** 9 + 7
N = 10 ** 5

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a, m=M):
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m
fact = [1, 1]
for i in range(2, N + 1):
	fact.append(fact[-1] * i % M)
numsPerRow = [i * (i + 1) // 2 + 1 for i in range(N)]

def findpos(x):
	i = bi.bisect_right(numsPerRow, x)
	return (i, x - numsPerRow[i - 1])
for _ in range(int(input())):
	(s, e) = list(map(int, input().split()))
	(srow, sidx) = findpos(s)
	(erow, eidx) = findpos(e)
	if erow <= srow or eidx < sidx or eidx - sidx > erow - srow:
		print(0)
	else:
		R = eidx - sidx
		L = erow - srow - R
		print(fact[L + R] * modinv(fact[L] * fact[R]) % M)


(Ln, mod) = (4 * 10 ** 4, 10 ** 9 + 7)
ft = [1] * Ln
for i in range(2, Ln):
	ft[i] = ft[i - 1] * i % mod
t = int(input())
for _ in range(t):
	h = 1
	(s, e) = map(int, input().split())
	if s > e:
		print(0)
		continue
	while h * (h + 1) // 2 < s:
		h += 1
	L = h
	while h * (h + 1) // 2 < e:
		h += 1
	H = h
	n = H - L
	r = e - H * (H - 1) // 2 + L * (L - 1) // 2 - s
	if n == 0 or n < r or r < 0:
		print(0)
		continue
	R = pow(ft[r], mod - 2, mod)
	NR = pow(ft[n - r], mod - 2, mod)
	print(ft[n] * R % mod * NR % mod)


import math

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
t = int(input())
while t > 0:
	(s, e) = map(int, input().split())
	x = math.sqrt(1 + 8 * s)
	y = math.sqrt(1 + 8 * e)
	s_row = math.ceil((x - 1) / 2)
	s_column = s - s_row * (s_row - 1) // 2
	e_row = math.ceil((y - 1) / 2)
	e_column = e - e_row * (e_row - 1) // 2
	r = e_column - s_column
	n = e_row - s_row
	p = int(1000000000.0 + 7)
	if n <= 0 or r < 0 or r > n:
		print(0)
	else:
		ans = ncr(n, r, p)
		print(ans)
	t = t - 1


import math
mod7 = 1000000007
MAXF = 100000

def powmod(a, b, p):
	a = a % p
	if a == 0:
		return 0
	product = 1
	while b > 0:
		if b % 2 == 1:
			product = product * a
			product = product % p
			b = b - 1
		a = a * a
		a = a % p
		b = b / 2
	return product

def inv(a, p):
	return powmod(a, p - 2, p)

def nCk(n, k, p):
	return fact[n] * inv(fact[k], p) % p * inv(fact[n - k], p) % p

def last_elem(level):
	return (level + 1) * level / 2

def get_level_index(n):
	level = -1
	index = -1
	if n == 1:
		return (1, 1)
	start = 2
	end = 1 + math.ceil(math.sqrt(2 * n))
	while start <= end:
		level = (start + end) / 2
		level = math.floor(level)
		if last_elem(level) >= n and last_elem(level - 1) < n:
			break
		elif last_elem(level) > n:
			end = level - 1
		else:
			start = level + 1
	index = n - level * (level - 1) / 2
	index = int(index)
	return (level, index)
fact = []
fact.append(1)
fact.append(1)
for i in range(MAXF + 1):
	i = i + 2
	fact.append(fact[i - 1] * i % mod7)
t = int(input())
for i in range(t):
	(s, e) = map(str, input().split(' '))
	s = int(s)
	e = int(e)
	(slevel, sindex) = get_level_index(s)
	(elevel, eindex) = get_level_index(e)
	L = elevel - slevel
	K = eindex - sindex
	ans = -1
	if L <= 0 or K < 0 or K > L:
		ans = 0
	else:
		ans = nCk(L, K, mod7)
	print(ans)


from bisect import bisect_left, bisect_right
N = 50000
fact = [1]
mod = 1000000007
for i in range(1, N + 1):
	fact.append(fact[-1] * i % mod)
arr = []
c = 1
for i in range(0, N):
	arr.append(c + i)
	c += i
t = int(input())
for i in range(t):
	(s, e) = map(int, input().split())
	x = bisect_right(arr, s) - 1
	y = bisect_right(arr, e) - 1
	df = y - x
	d1 = s - arr[x]
	d2 = arr[x + 1] - s - 1
	d3 = e - arr[y]
	d4 = arr[y + 1] - e - 1
	if s > e:
		print(0)
	elif d3 < d1 or d4 < d2:
		print(0)
	else:
		num = fact[df]
		den = fact[df - (e - arr[y] - d1)] * fact[e - arr[y] - d1] % mod
		ans = num * pow(den, mod - 2, mod) % mod
		print(ans)


import math

def ind_level(a, dic):
	if a == 0:
		return (-1, -1)
	if a == 1:
		return (1, 1)
	else:
		st = 2
		end = 49999
		while st <= end:
			m = (st + end) // 2
			if dic[m][0] <= a and dic[m][1] >= a:
				return (m, a - dic[m][0] + 1)
			elif dic[m][0] > a:
				end = m - 1
			elif dic[m][1] < a:
				st = m + 1

def pmd(a, b, c):
	a %= c
	if a == 0:
		return 0
	prod = 1
	while b > 0:
		if b % 2 == 1:
			prod *= a
			prod %= c
			b -= 1
		a *= a
		a %= c
		b /= 2
	return prod

def inv(a, p):
	return pmd(a, p - 2, p)

def ncr(n, k, p):
	return fact[n] * inv(fact[k], p) % p * inv(fact[n - k], p) % p
t = int(input())
dic = {}
for i in range(1, 50000):
	k = i * (i + 1) // 2
	dic[i] = [k - i + 1, k, i]
mod = 10 ** 9 + 7
fact = [1, 1]
for i in range(2, 50000):
	fact.append(i * fact[i - 1] % mod)
for i in range(t):
	[a, b] = list(map(int, input().split()))
	if a > b:
		print(0)
	else:
		(lvl1, ind1) = ind_level(a, dic)
		(lvl2, ind2) = ind_level(b, dic)
		ldif = lvl2 - lvl1
		idif = ind2 - ind1
		if ldif <= 0 or idif < 0 or ldif < idif:
			print(0)
		elif ldif == idif:
			print(1)
		else:
			print(int(ncr(ldif, idif, mod)))


import math
t = int(input())
mod = 10 ** 9 + 7
fact = [1, 1]
for i in range(2, 50000):
	fact.append(fact[-1] * i % mod)

def modInv(val):
	return pow(val, mod - 2, mod)

def getRow(val):
	row = math.ceil((-1 + math.sqrt(1 + 8 * val)) / 2)
	return row

def getCol(row, val):
	last = row * (row + 1) // 2
	return row - (last - val)
for _ in range(t):
	(s, e) = map(int, input().split())
	if s > e:
		print(0)
	else:
		r1 = getRow(s)
		c1 = getCol(r1, s)
		r2 = getRow(e)
		c2 = getCol(r2, e)
		r1 -= 1
		c1 -= 1
		r2 -= 1
		c2 -= 1
		if c2 - c1 >= 0 and c2 - c1 <= r2 - r1:
			r = r2 - r1
			c = c2 - c1
			ans = fact[r] * modInv(fact[c]) % mod * modInv(fact[r - c]) % mod % mod
			print(ans)
		else:
			print(0)


from math import *
t = int(input())
for _ in range(t):
	(s, e) = map(int, input().split())

	def getRow(x):
		return int((1 + (8 * x - 3) ** 0.5) / 2)

	def getCol(x, n):
		return x - n * (n - 1) // 2

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

	def nCr(n, r, p):
		res = 1
		res1 = 1
		for i in range(r):
			res *= n - i
			res %= p
			res1 *= i + 1
			res1 %= p
		return res * pow(res1, p - 2, p) % p
	x1 = getRow(s)
	x2 = getRow(e)
	y1 = getCol(s, x1)
	y2 = getCol(e, x2)
	d = x2 - x1
	r = y2 - y1
	if d >= 0 and d >= r and (r >= 0):
		y = nCr(d, r, 10 ** 9 + 7)
		print(int(y) % (10 ** 9 + 7))
	else:
		print(0)


mod = 10 ** 9 + 7

def GetPosition(x):
	last_complete_row = (-1 + (1 + 8 * x) ** 0.5) // 2
	remainder = x - last_complete_row * (last_complete_row + 1) // 2
	if remainder:
		row = last_complete_row + 1
		col = remainder
		return (int(row), int(col))
	row = col = last_complete_row
	return (int(row), int(col))

def ModInverse(n):
	return pow(n, mod - 2, mod)

def NChooseK(n, k):
	numerator = factorial[n]
	denom = factorial[n - k] * factorial[k] % mod
	return numerator * ModInverse(denom) % mod
factorial = [1]
for n in range(1, 46000):
	factorial += [factorial[-1] * n % mod]
num_test_cases = int(input())
for _ in range(num_test_cases):
	(x_start, x_end) = [int(x) for x in input().split()]
	(row_start, col_start) = GetPosition(x_start)
	(row_end, col_end) = GetPosition(x_end)
	rows_down = row_end - row_start
	cols_over = col_end - col_start
	if rows_down < 0 or cols_over < 0 or cols_over > rows_down:
		print(0)
		continue
	ans = NChooseK(rows_down, cols_over)
	print(ans)


import math
mod = int(1000000000.0 + 7)

def sum_natural(n):
	return n * (n + 1) / 2

def binary_search(n, st, end):
	if n == 1:
		return 1
	if end >= st:
		level = st + (end - st) // 2
		if sum_natural(level) >= n and sum_natural(level - 1) < n:
			return level
		elif sum_natural(level) > n:
			return binary_search(n, st, level - 1)
		else:
			return binary_search(n, level + 1, end)

def fact(n):
	dp = [0] * (n + 1)
	dp[0] = 1
	for i in range(1, n + 1):
		dp[i] = dp[i - 1] * i % mod
	return dp

def powmod(a, b, p):
	a %= p
	if a == 0:
		return 0
	product = 1
	while b > 0:
		if b % 2 == 1:
			product *= a
			product %= p
			b -= 1
		a *= a
		a %= p
		b /= 2
	return product

def inv(a, p):
	return powmod(a, p - 2, p)

def ncr(n, r, precomp_fact):
	return precomp_fact[n] * inv(precomp_fact[r], mod) % mod * inv(precomp_fact[n - r], mod) % mod

def solve(precomp_fact):
	(s, e) = list(map(int, input().split()))
	if s > e:
		print(0)
		return 0
	level_s = int(binary_search(s, 2, 10000000000.0))
	level_e = int(binary_search(e, 2, 10000000000.0))
	idx_s = int(s - sum_natural(level_s - 1))
	idx_e = int(e - sum_natural(level_e - 1))
	diff_l = level_e - level_s
	diff_idx = idx_e - idx_s
	if diff_l < 0 or diff_idx < 0 or diff_idx > diff_l:
		print(0)
		return
	ans = ncr(diff_l, diff_idx, precomp_fact)
	print(int(ans))
precomp_facts = fact(10000000)
t = int(input())
while t:
	solve(precomp_facts)
	t -= 1


t = int(input().strip())

def get_row_starting_cell(row):
	return 1 + row * (row - 1) // 2

def get_position(cell):
	(l, r) = (1, int(100000.0))
	while l + 1 < r:
		m = l + (r - l) // 2
		starting_cell = get_row_starting_cell(m)
		if starting_cell > cell:
			r = m
		else:
			l = m
	assert get_row_starting_cell(l) <= cell < get_row_starting_cell(l + 1)
	return (l, cell - get_row_starting_cell(l) + 1)
MOD = int(1000000000.0) + 7

def get_inverse_modulo(i, mod=MOD):
	return pow(i, mod - 2, mod)
inverse_factorial_modulo = [0] * int(100000.0)
inverse_factorial_modulo[0] = 1
for i in range(1, int(100000.0)):
	inverse_factorial_modulo[i] = inverse_factorial_modulo[i - 1] * get_inverse_modulo(i) % MOD

def ncr(n, r):
	r = min(r, n - r)
	start = 1
	for i in range(n + 1 - r, n + 1):
		start = start * i % MOD
	start = start * inverse_factorial_modulo[r] % MOD
	return start
for _ in range(t):
	(start, end) = map(int, input().strip().split())
	(start_x, start_y) = get_position(start)
	(end_x, end_y) = get_position(end)
	offset_x = end_x - start_x
	offset_y = end_y - start_y
	if offset_y < 0 or offset_y > offset_x:
		print(0)
		continue
	print(ncr(offset_x, offset_y))


def pyramid(s, e):
	if e <= s:
		print(0)
		return
	d1 = int((1 + (8 * s - 7) ** 0.5) / 2)
	d2 = int((1 + (8 * e - 7) ** 0.5) / 2)
	n = abs(d2 - d1)
	h1 = s - d1 * (d1 - 1) // 2
	h2 = e - d2 * (d2 - 1) // 2
	r = int(abs(h2 - h1))
	if h1 > h2 or abs(h1 - h2) > abs(d1 - d2):
		print(0)
		return
	elif h1 == h2 or abs(h1 - h2) == abs(d1 - d2):
		print(1)
		return
	k = 1000000007
	print(int(ncr(n, r, k)))
	return

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
t = int(input())
for _ in range(t):
	(s, e) = map(int, input().split())
	pyramid(s, e)


def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
t = int(input())
for _ in range(t):
	(s, e) = map(int, input().split())
	if e <= s:
		print(0)
	else:
		d_s = (1 + (8 * s - 7) ** 0.5) / 2
		d_s = int(d_s)
		d_e = (1 + (8 * e - 7) ** 0.5) / 2
		d_e = int(d_e)
		h_s = s - 1 - d_s * (d_s - 1) // 2
		h_e = e - 1 - d_e * (d_e - 1) // 2
		if abs(h_s - h_e) > abs(d_s - d_e):
			print(0)
		elif abs(h_s - h_e) == abs(d_s - d_e) or h_s - h_e == 0:
			print(1)
		elif h_e - h_s < 0:
			print(0)
		else:
			print(int(ncr(d_e - d_s, abs(h_s - h_e), 1000000007)))


from math import ceil
from math import sqrt
mod = 10 ** 9 + 7

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

def last_ele(n):
	return int(n * (n + 1) / 2)

def hi(block):
	lvl = -1
	if block == 1:
		return (1, 1)
	st = 2
	end = 1 + ceil(sqrt(2 * block))
	while st <= end:
		lvl = int((st + end) / 2)
		if last_ele(lvl) >= block and last_ele(lvl - 1) < block:
			break
		elif last_ele(lvl) > block:
			end = lvl - 1
		else:
			st = lvl + 1
	index = block - int(lvl * (lvl - 1) / 2)
	return (lvl, index)
t = int(input())
for z in range(t):
	(x, y) = map(int, input().split())
	if x > y:
		print(0)
	else:
		(hx, ix) = hi(x)
		(hy, iy) = hi(y)
		L = hy - hx
		K = iy - ix
		if L <= 0 or K < 0 or K > L:
			print(0)
		else:
			print(ncr(L, K, mod))


P = 1000000000.0 + 7

def find_location(index):
	i = 1
	max_idx = 0
	while True:
		max_idx += i
		if max_idx >= index:
			lvl = i
			idx = lvl - (max_idx - index)
			return (lvl, idx)
		i += 1

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

def main():
	T = int(input())
	for tc in range(T):
		(e, s) = map(int, input().split(' '))
		(s_lvl, s_idx) = find_location(s)
		(e_lvl, e_idx) = find_location(e)
		lvl = s_lvl - e_lvl
		idx = s_idx - e_idx
		if idx < 0 or s_lvl < e_lvl or (s_lvl == e_lvl and s_idx != e_idx):
			print(0)
		else:
			print(ncr(lvl, idx, int(1000000000.0 + 7)))
main()


def sumofn(n):
	return int(n * (n + 1) / 2)

def level_search(n):
	l = 0
	r = 44725
	while l <= r:
		mid = l + (r - l) // 2
		if sumofn(mid) >= n and sumofn(mid - 1) < n:
			return mid
		elif sumofn(mid) > n:
			r = mid - 1
		elif sumofn(mid) < n:
			l = mid + 1

def index(a, l):
	return int(a - l * (l - 1) / 2)

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
t = int(input())
for _ in range(t):
	(s, e) = list(map(int, input().split(' ')))
	level_s = level_search(s)
	level_e = level_search(e)
	index_s = index(s, level_s)
	index_e = index(e, level_e)
	diff_level = level_e - level_s
	diff_index = index_e - index_s
	ans = 1
	if diff_level <= 0 or diff_index < 0 or diff_index > diff_level:
		ans = 0
	else:
		ans = ncr(diff_level, diff_index, 1000000007)
	print(int(ans))


import math
p = 1000000007
t = int(input())
for i in range(t):
	(s, e) = map(int, input().split())
	m = math.ceil(math.sqrt(2 * s))
	x = s - m * (m - 1) / 2 - 1
	while x < 0:
		m -= 1
		x = s - m * (m - 1) / 2 - 1
	n = math.ceil(math.sqrt(2 * e))
	y = -1
	y = e - n * (n - 1) / 2 - 1
	while y < 0:
		n -= 1
		y = e - n * (n - 1) / 2 - 1
	a = int(n - m)
	b = int(y - x)
	if b < 0 or a < 0 or b > a:
		print(0)
	else:
		num = 1
		den = 1
		r = min(b, a - b)
		for i in range(r):
			num = num * (a - i) % p
			den = den * (i + 1) % p
		print(num * pow(den, p - 2, p) % p)


from math import ceil, sqrt, factorial
fact = [1]
for i in range(1, 44721):
	fact.append(fact[-1] * i)

def powmod(a, b, p):
	a %= p
	if a == 0:
		return 0
	product = 1
	while b > 0:
		if b % 2 == 1:
			product *= a
			product %= p
			b -= 1
		a *= a
		a %= p
		b /= 2
	return product

def inv(a, p):
	return powmod(a, p - 2, p)

def nCk(n, k, p):
	return fact[n] * inv(fact[k], p) % p * inv(fact[n - k], p) % p

def suum(n):
	l = ceil(((8 * n + 1) ** 0.5 - 1) / 2)
	num = (l ** 2 - l + 2) // 2
	return (l, n - num)
for _ in range(int(input())):
	(s, e) = list(map(int, input().split()))
	if e > s:
		s = suum(s)
		e = suum(e)
		l = e[0] - s[0]
		k = e[1] - s[1]
		if l > 0 and k >= 0 and (l >= k):
			print(nCk(l, k, 1000000007))
		else:
			print(0)
	else:
		print(0)


import math

def findIndex(t):
	x = (t - 1) * 2
	if 1 + 4 * x < 0:
		ind1 = 0
	else:
		k = math.sqrt(1 + 4 * x)
		if -1 + k >= 0:
			ind1 = (-1 + k) // 2
		else:
			ind1 = (-1 + k) // 2
	first = ind1 * (ind1 + 1) // 2 + 1
	ind2 = t - first
	return (int(ind1), int(ind2))
t = int(input())
for _ in range(t):
	(s, e) = map(int, input().split())
	if s > e:
		print(0)
		continue
	if s == e:
		print(1)
		continue
	(sr, sc) = findIndex(s)
	(er, ec) = findIndex(e)
	if sc + (er - sr) < ec or ec < sc:
		print(0)
		continue
	i = er - sr
	j = ec - sc
	numerator = denominator = 1
	for x in range(j):
		numerator = numerator * (i - x) % 1000000007
		denominator = denominator * (x + 1) % 1000000007
	res = numerator * pow(denominator, 1000000007 - 2, 1000000007) % 1000000007
	print(res)


import math
BIG_NUMBER = 7 + 10 ** 9
factorial = dict()
factorial[0] = 1
for i in range(1, 200000):
	factorial[i] = factorial[i - 1] * i % BIG_NUMBER

def get_first_element(row):
	return 1 + row * (row - 1) / 2

def get_last_element(row):
	return row * (row + 1) / 2

def is_in_row(number, row):
	if row < 1:
		return False
	elif row == 1:
		return number == 1
	row_start = row * (row - 1) / 2 + 1
	row_end = row * (row + 1) / 2
	return row_start <= number <= row_end

def get_row_number(number):
	if number == 1:
		return 1
	elif number <= 3:
		return 2
	temp_float = math.sqrt(2.0 * number)
	temp_int = int(temp_float)
	possible_rows = [temp_int, temp_int + 1]
	for row in possible_rows:
		if is_in_row(number, row):
			return row
	return temp_int

def get_width_from_center(number, row):
	middle = (float(get_first_element(row)) + float(get_last_element(row))) / 2.0
	return middle - float(number)

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

def mod_inverse(n, p):
	return power(n, p - 2, p)

def num_combinations(n, r, p):
	return factorial[n] * mod_inverse(factorial[r], p) % p * (mod_inverse(factorial[n - r], p) % p) % p

def compute_num_paths(start, end):
	if start >= end:
		return 0
	start_row = get_row_number(start)
	end_row = get_row_number(end)
	height_diff = end_row - start_row
	if height_diff <= 0:
		return 0
	start_width = get_width_from_center(start, start_row)
	end_width = get_width_from_center(end, end_row)
	width_diff = int(math.fabs(2.0 * (end_width - start_width)))
	if width_diff > height_diff:
		return 0
	if width_diff == height_diff:
		return 1
	num_lefts = int((height_diff + width_diff) / 2.0)
	num_rights = int((height_diff - width_diff) / 2.0)
	return num_combinations(height_diff, num_lefts, BIG_NUMBER)
for _ in range(int(input())):
	(s, e) = list(map(int, input().strip().split(' ')))
	print(compute_num_paths(s, e))


def get_rows(start, end):
	j = 1
	k = 1
	got_start = False
	value = [0, 0]
	while True:
		if not got_start and start <= j:
			value[0] = k
			got_start = True
		elif end <= j:
			value[1] = k
			return value
		k += 1
		j += k

def ncrmodm(n, r, m):
	if r == 0 or r == n:
		return 1
	up = 1
	down = 1
	for i in range(r):
		up = up * (n - i) % m
		down = down * (i + 1) % m
	return up * pow(down, m - 2, m) % m
for _ in range(int(input())):
	(s, e) = map(int, input().split(' '))
	m = 7 + 10 ** 9
	if s >= e:
		print(0)
		continue
	(srow, erow) = get_rows(s, e)
	step = erow - srow
	s += erow * (erow + 1) // 2 - srow * (srow + 1) // 2
	side = s - e
	if side > 0:
		if side > step:
			print(0)
		else:
			if side > step - side:
				side = step - side
			print(ncrmodm(step, side, m))
	elif side == 0:
		print(1)
	else:
		print(0)


import sys
import math
mod = 1000000007
mx = 10 ** 5
fact = [0] * mx
fact[0] = 0
fact[1] = 1
for x in range(2, mx):
	fact[x] = fact[x - 1] * x % mod

def powmod(a, b, p):
	a %= p
	if a == 0:
		return 0
	product = 1
	while b > 0:
		if b & 1:
			product *= a
			product %= p
			--b
		a *= a
		a %= p
		b //= 2
	return product

def inv(a, p):
	return powmod(a, p - 2, p)

def nCk(n, k, p):
	return fact[n] * inv(fact[k], p) % p * inv(fact[n - k], p) % p

def preCalculation(N, another):
	mod = 1000000007
	if another == 1:
		return 1
	else:
		return nCk(N, another - 1, mod)

def res(ls):
	tar = ls[0]
	lo = 1
	hi = 10000000
	mod = 1000000007
	ans = -1
	while lo <= hi:
		mid = (lo + hi) // 2
		chk = mid * (mid + 1) // 2
		if tar == chk:
			ans = mid
			break
		elif tar < chk:
			ans = mid
			hi = mid - 1
		else:
			lo = mid + 1
	tar1 = ls[1]
	lo = 1
	hi = 10000000
	ans1 = -1
	while lo <= hi:
		mid = (lo + hi) // 2
		chk = mid * (mid + 1) // 2
		if tar1 == chk:
			ans1 = mid
			break
		elif tar1 < chk:
			ans1 = mid
			hi = mid - 1
		else:
			lo = mid + 1
	reqRight = ans1 * (ans1 + 1) // 2 - ans * (ans + 1) // 2
	reqLeft = ans1 * (ans1 - 1) // 2 - ans * (ans - 1) // 2
	reqRight += ls[0]
	reqLeft += ls[0]
	if reqLeft <= ls[1] <= reqRight:
		req = preCalculation(ans1 - ans, min((ans1 - ans - (ls[1] - reqLeft), ls[1] - reqLeft)) + 1)
		return req % mod
	else:
		return 0

def get_ints():
	return map(int, sys.stdin.readline().strip().split())
for tc in range(int(input())):
	(a, b) = get_ints()
	print(res([a, b]))


mod = pow(10, 9) + 7
a = [0] * 100000
a[0] = 1
for i in range(1, len(a)):
	a[i] = a[i - 1] * i % mod

def cos(x):
	p = pow(1 + 8 * x, 0.5) - 1
	p //= 2
	if (p * p + p) // 2 < x:
		p += 1
	return int(p)

def solve():
	(s, e) = map(int, input().split())
	x1 = cos(s)
	x2 = cos(e)
	y1 = s - (x1 * x1 - x1) // 2
	y2 = e - (x2 * x2 - x2) // 2
	y11 = (x1 * x1 + x1) // 2 - s
	y22 = (x2 * x2 + x2) // 2 - e
	if y2 < y1 or y11 > y22:
		print(0)
		return
	n = x2 - x1
	r = y2 - y1
	ncr = a[n] * pow(a[r], mod - 2, mod) % mod * pow(a[n - r], mod - 2, mod) % mod
	print(ncr)
for iii in range(int(input())):
	solve()


import math
N = 1000001
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)

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

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

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

def Binomial(N, R, p):
	ans = fact[N] * factorialNumInverse[R] % p * factorialNumInverse[N - R] % p
	return ans
InverseofNumber(10 ** 9 + 7)
InverseofFactorial(10 ** 9 + 7)
factorial(10 ** 9 + 7)

def lev(n):
	return math.ceil((-1 + (1 + 8 * n) ** 0.5) / 2)

def bs(n, x):
	return x - n * (n - 1) // 2
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	d2 = bs(lev(y), y) - bs(lev(x), x)
	d1 = lev(y) - lev(x)
	if d1 <= 0 or d2 < 0 or d2 > d1:
		print(0)
	else:
		d1 = abs(lev(x) - lev(y))
		print(Binomial(d1, d2, 10 ** 9 + 7))


MODULO = 10 ** 9 + 7

def combination(n):
	return n * (n + 1) // 2

def isGreater(row, s):
	if combination(row) >= s:
		return 1
	else:
		return 0

def get_coordinates(num):
	row = gRow(num)
	hd = get_horizontal_dist(row, num)
	return (row, hd)

def gRow(s):
	ans = -1
	l = 1
	h = 10 ** 9
	while l <= h:
		mid = l + (h - l) // 2
		if isGreater(mid, s):
			best = mid
			h = mid - 1
		else:
			l = mid + 1
	return best

def get_horizontal_dist(row, num):
	midne = combination(row - 1) + 1
	column = num - midne
	start = 1 - row
	return start + 2 * column

def nComb_r(n, r, p):
	num = 1
	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
t = int(input())
for _ in range(t):
	(s, e) = list(map(int, input().split()))
	(r1, hd1) = get_coordinates(s)
	(r2, hd2) = get_coordinates(e)
	hdiff = abs(hd1 - hd2)
	if hdiff > r2 - r1:
		print(0)
	else:
		nhd = hd2 - hd1
		r2 -= r1
		r1 = 0
		startcolumn = -r2
		col = (nhd - startcolumn) // 2
		n = r2
		ans = nComb_r(n, col, MODULO)
		print(ans)


from math import gcd

def comb(n):
	return n * (n + 1) // 2

def isGreater(row, s):
	return comb(row) >= s
MOD = 10 ** 9 + 7

def get_row(s):
	best = -1
	lo = 1
	hi = 10 ** 9
	while lo <= hi:
		mi = lo + hi >> 1
		if isGreater(mi, s):
			best = mi
			hi = mi - 1
		else:
			lo = mi + 1
	return best

def get_horizontal_dist(row, num):
	mine = comb(row - 1) + 1
	col = num - mine
	start = 1 - row
	return start + 2 * col

def get_coordinates(num):
	row = get_row(num)
	hd = get_horizontal_dist(row, num)
	return (row, hd)

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
t = int(input())
for _ in range(t):
	(s, e) = list(map(int, input().split()))
	(r1, hd1) = get_coordinates(s)
	(r2, hd2) = get_coordinates(e)
	hdiff = abs(hd1 - hd2)
	if hdiff > r2 - r1:
		print(0)
	else:
		newhd1 = 0
		newhd2 = hd2 - hd1
		r2 -= r1
		r1 = 0
		start_col = -r2
		col = (newhd2 - start_col) // 2
		n = r2
		ans = ncr(n, col, MOD)
		print(ans)


import math
from random import randint

def timeTaken(func):
	from time import time

	def decorator(*args, **kwargs):
		start = time()
		returned = func(*args, **kwargs)
		end = time()
		if int(100 * (end - start)) / 100 > 0.01:
			print('Time taken is: ', int(100 * (end - start)) / 100, 'Sec')
		return returned
	return decorator

def memoize(func):
	mem = {}

	def memoizer(*args, **kwargs):
		key = str(args) + str(kwargs)
		if key not in mem:
			mem[key] = func(*args, **kwargs)
		return mem[key]
	return memoizer

def counter(lst):
	q = [0] * max(lst)
	for i in range(len(lst)):
		q[lst[i] - 1] = q[lst[i] - 1] + 1
	return q

def counter_elements(lst):
	q = dict()
	for i in range(len(lst)):
		if lst[i] not in q:
			q[lst[i]] = 0
		q[lst[i]] = q[lst[i]] + 1
	return q

def string_counter(lst):
	q = [0] * 26
	for i in range(len(lst)):
		q[ord(lst[i]) - 97] = q[ord(lst[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.extend([i, n // i])
	return q

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return q

def power_two(x):
	return x and (not x & x - 1)

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

def getPrimes(MAX=10 ** 5):
	primes = [2]
	for n in range(3, MAX, 2):
		sqrt_n = math.sqrt(n)
		for prime in primes:
			if prime > sqrt_n:
				primes.append(n)
				break
			if n % prime == 0:
				break
	return primes

def sieve(MAX=10 ** 5):
	spf = [i for i in range(MAX)]
	for i in range(4, MAX, 2):
		spf[i] = 2
	for i in range(3, math.ceil(math.sqrt(MAX))):
		if spf[i] == i:
			for j in range(i * i, MAX, i):
				if spf[j] == j:
					spf[j] = i
	return spf
MOD = 10 ** 9 + 7

def mod_mul(a, b):
	return a % MOD * (b % MOD) % MOD

def mod_sum(a, b):
	return (a + b) % MOD

def mod_inv(a):
	return pow(a, MOD - 2, MOD)
import io, os, sys
input = sys.stdin.readline

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

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

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

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

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

def outlt(lst):
	sys.stdout.write(' '.join(map(str, lst)) + '\n')

def outplt(lst):
	sys.stdout.write('\n'.join(map(str, lst)))

def qA(N, A):
	d = {}
	for a in A:
		d[a] = d[a] + 1 if a in d else 1
	mx = max(d.values())
	if mx == N:
		return 0
	elif mx == 1:
		return -1
	else:
		return N - mx + 1

def qB(N, M):
	if N == M:
		return '01' * (N + 1)
	elif N > M:
		return '01' * M + '010' * (N - M)
	else:
		return '10' * N + '101' * (M - N)

def qC(N, S):
	seq = {'R': 'P', 'P': 'S', 'S': 'R'}

	def rps(x, y):
		return x if x == y or x == seq[y] else y
	w = [{'R': None, 'P': None, 'S': None} for x in range(N - 1)]
	w.append({x: rps(x, S[N - 1]) for x in 'RPS'})
	for i in range(N - 1):
		x = N - i - 2
		for y in 'RPS':
			w[x][y] = w[x + 1][rps(y, S[x + 1])]
	ans = ''
	for i in range(N):
		ans += w[i][S[i]]
	return ans

def qD(N, A):
	c = [[[0, 0] for x in range(N)] for y in range(N)]
	c[0][0] = [int(A[0][0]), int(A[0][0])]
	for i in range(1, N):
		c[i][0] = [1, c[i - 1][0][1] + 1] if A[i][0] == '1' else [0, 0]
		c[0][i] = [c[0][i - 1][0] + 1, 1] if A[0][i] == '1' else [0, 0]
	for i in range(1, N):
		for j in range(1, N):
			if A[i][j] == '1':
				(c[i][j][0], c[i][j][1]) = (c[i][j - 1][0] + 1, c[i - 1][j][1] + 1)
	ans = sum((sum((1 for a in A[y] if a == '1')) for y in range(N)))
	for col in range(N):
		for row in range(N):
			if c[row][col][1] and c[row][col][0]:
				for l in range(row + 1, N):
					wd = l - row
					if c[l][col][1] == 0 or wd > N - 1 - col:
						break
					if c[row][col + wd][0] >= wd and c[l][col + wd][1] >= wd and (c[l][col + wd][0] >= wd):
						ans += 1
	return ans

def factorials(n):
	facts = [1, 1]
	for i in range(2, n + 1):
		facts.append(facts[-1] * i % MOD)
	return facts
fact = factorials(100000)

def numberOfPaths(m, n):
	return fact[m + n - 2] * mod_inv(mod_mul(fact[n - 1], fact[m - 1])) % MOD

def rowNum(x):
	ans = ((1 + x * 8) ** 0.5 - 1) / 2
	return int(ans) if ans == int(ans) else int(ans) + 1

def colNum(row, x):
	return x - row * (row - 1) // 2

def qE(s, e):
	(r1, r2) = (rowNum(s), rowNum(e))
	(c1, c2) = (colNum(r1, s), colNum(r2, e))
	m = abs(c1 - c2)
	return 0 if c2 < c1 or c2 - c1 > r2 - r1 or r2 <= r1 else numberOfPaths(m + 1, r2 - r1 - m + 1)
for _ in range(inp()):
	(s, e) = inlt()
	outp(qE(s, e))


import math
MAXN = 100000
MODVAL = 1000000007

def getCoeff(n, k, fact):
	return fact[n] * pow(fact[n - k], MODVAL - 2, MODVAL) * pow(fact[k], MODVAL - 2, MODVAL) % MODVAL

def getRow(x):
	return math.ceil((math.sqrt(8 * x + 1) - 1) / 2)

def getCol(x, r):
	return x - r * (r - 1) // 2

def getAns(a, b, fact):
	(rA, rB) = (getRow(a), getRow(b))
	(cA, cB) = (getCol(a, rA), getCol(b, rB))
	if rB <= rA:
		return 0
	if abs(cA - cB) > rB - rA:
		return 0
	if cB < cA:
		return 0
	else:
		(right, left) = (cB - cA, rB - rA - (cB - cA))
	return getCoeff(left + right, right, fact)

def main():
	fact = [-1 for _ in range(MAXN)]
	(fact[0], fact[1]) = (1, 1)
	for i in range(2, MAXN):
		fact[i] = fact[i - 1] * i % MODVAL
	n = int(input())
	for _ in range(n):
		[a, b] = list(map(int, input().split()))
		print(getAns(a, b, fact))
main()


MOD = pow(10, 9) + 7
level_ends = [0]
factorial = [1, 1]
for i in range(1, 50000):
	factorial.append((i + 1) * factorial[-1] % MOD)
	temp = i * (i + 1) >> 1
	if temp <= MOD - 7:
		level_ends.append(temp)
	else:
		level_ends.append(temp)
		break

def inverse(a, b, m):
	a = a % m
	if a == 0:
		return 0
	product = 1
	while b > 0:
		if b % 2 == 1:
			product = product * a
			product = product % m
			b = b - 1
		a = a * a
		a = a % m
		b = int(b / 2)
	return product

def calculate(n, k, m):
	return factorial[n] * inverse(factorial[k], m - 2, m) % m * inverse(factorial[n - k], m - 2, m) % m

def find_level(n, start, end):
	for i in range(0, len(level_ends) - 1):
		if level_ends[i] < n <= level_ends[i + 1]:
			return i
t = int(input())
while t != 0:
	(start, end) = input().split()
	start = int(start)
	end = int(end)
	start_level = -1
	end_level = -1
	start_level = find_level(start, 0, len(level_ends))
	end_level = find_level(end, 0, len(level_ends))
	end_left = level_ends[end_level] - level_ends[start_level] + start
	end_right = level_ends[end_level + 1] - level_ends[start_level] - start_level + start - 1
	ans = 0
	if end_left <= end <= end_right:
		modified_end_level = end_level - start_level
		modified_column = end - end_left
		ans = calculate(modified_end_level, modified_column, MOD)
	print(ans)
	t -= 1


import math as m
N = 1000001
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)

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

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

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

def Binomial(N, R, p):
	ans = fact[N] * factorialNumInverse[R] % p * factorialNumInverse[N - R] % p
	return ans

def comb(n, r):
	(ans, div) = (1, 1)
	if r > n / 2:
		r = n - r
	for i in range(r):
		ans = ans * (n - i)
		div = div * (i + 1)
	return ans // div

def F_index(n):
	a = m.floor(m.sqrt(2 * n))
	if n <= (a * a + a) // 2:
		x = a
	else:
		x = a + 1
	y = n - (x * x - x) // 2
	return (x, y)
(t, L, p) = (int(input()), [], 10 ** 9 + 7)
InverseofNumber(p)
InverseofFactorial(p)
factorial(p)
for i in range(t):
	l = input().split(' ')
	(start, destn) = (int(l[0]), int(l[1]))
	(x1, y1) = F_index(start)
	(x2, y2) = F_index(destn)
	(n, r) = (x2 - x1, y2 - y1)
	if n <= 0 or r < 0 or r > n:
		L.append(0)
	else:
		L.append(Binomial(n, r, p))
for i in range(t):
	print(L[i])


import bisect
from math import factorial
lista = [n * (n + 1) // 2 for n in range(1, 44722)]

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
for _ in range(int(input())):
	(start, end) = map(int, input().split())
	if start >= end:
		print(0)
	elif start == 1:
		diag = bisect.bisect_left(lista, end)
		kend = lista[diag] - end
		if nstart <= nend and kstart <= kend:
			print(ncr(diag, kend, 1000000007))
		else:
			print(0)
	else:
		diag = bisect.bisect_left(lista, start)
		kstart = lista[diag] - start
		nstart = lista[diag] - lista[diag - 1] - kstart - 1
		diag1 = bisect.bisect_left(lista, end)
		kend = lista[diag1] - end
		nend = lista[diag1] - lista[diag1 - 1] - kend - 1
		if nstart <= nend and kstart <= kend:
			print(ncr(diag1 - diag, kend - kstart, 1000000007))
		else:
			print(0)


from math import ceil
mod = 10 ** 9 + 7

def power(a, b, p):
	ans = 1
	a = a % p
	while b:
		if b & 1:
			ans = ans * a % p
		b = b >> 1
		a = a * a % p
	return ans

def inverse_mod(n, p):
	return power(n, p - 2, p)

def nCr(n, r, p):
	if n < r:
		return 0
	if r == 0:
		return 1
	y = [0] * (n + 1)
	y[0] = 1
	y[1] = 1
	for i in range(2, n + 1):
		y[i] = i * y[i - 1] % p
	return y[n] * inverse_mod(y[r], p) % p * (inverse_mod(y[n - r], p) % p) % p

def func(x):
	ans = ceil(((1 + 8 * x) ** 0.5 - 1) / 2)
	return ans

def func1(n, x):
	num = (x - 1) * x // 2
	return n - num
for u in range(int(input())):
	(s, e) = map(int, input().split())
	row_n1 = func(s)
	row_n2 = func(e)
	d1 = row_n2 - row_n1
	idx_n1 = func1(s, row_n1)
	idx_n2 = func1(e, row_n2)
	d2 = idx_n2 - idx_n1
	if d1 <= 0 or d2 < 0 or d1 < d2:
		print(0)
	else:
		print(nCr(d1, d2, mod))


import math

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
for _ in range(int(input())):
	(st, en) = [int(s) for s in input().split()]
	aa = math.floor(math.sqrt(2 * st))
	if st <= (aa * aa + aa) // 2:
		sti = aa
	else:
		sti = aa + 1
	stj = st - (sti * sti - sti) // 2
	aa = math.floor(math.sqrt(2 * en))
	if en <= (aa * aa + aa) // 2:
		eni = aa
	else:
		eni = aa + 1
	enj = en - (eni * eni - eni) // 2
	if sti > eni or stj > enj:
		print(0)
		continue
	if sti == eni and stj == enj:
		print(0)
		continue
	(i, j) = (eni - sti, enj - stj)
	(mx, mn) = (max(i, j), min(i, j))
	print(ncr(i, j, 10 ** 9 + 7))


import math
mod7 = 10 ** 9 + 7
max = 10 ** 5
fact = [1, 1]
for i in range(2, max + 1):
	fact.append(i * fact[i - 1] % mod7)

def findLevelAndIndex(num):
	if num == 1:
		return (1, 0)
	start = 2
	end = 1 + math.ceil(math.sqrt(2 * num))
	while start <= end:
		mid = int((start + end) / 2)
		if mid * (mid + 1) / 2 >= num > mid * (mid - 1) / 2:
			level = mid
			break
		elif num > mid * (mid + 1) / 2:
			start = mid
		else:
			end = mid
	return (level, num - (level * (level - 1) / 2 + 1))

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

def modInverse(a, p):
	return power(a, p - 2, p)

def choose(n, k):
	return fact[n] * (modInverse(fact[k], mod7) % mod7) * modInverse(fact[n - k], mod7) % mod7
t = int(input())
for _ in range(t):
	(s, e) = map(int, input().split())
	(Sl, Si) = map(int, findLevelAndIndex(s))
	(El, Ei) = map(int, findLevelAndIndex(e))
	Dl = El - Sl
	Di = Ei - Si
	if Dl > 0 and Dl >= Di >= 0:
		ans = choose(Dl % mod7, Di % mod7) % mod7
		print(ans)
	else:
		print(0)


import math

def cord(a):
	x = ((1 + 8 * a) ** 0.5 - 1) / 2
	if x % 1 == 0:
		x = int(x)
	else:
		x = int(x) + 1
	y = int(a - x * (x - 1) / 2)
	return (x, y)

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

def way(s, e):
	(sx, sy) = cord(s)
	(ex, ey) = cord(e)
	x = ex - sx
	y = ey - sy
	z = x - y
	if x < 1 or y < 0 or z < 0:
		return 0
	ans = ncr(y + z, min(y, z), 1000000007)
	return ans
for i in range(int(input())):
	(s, e) = map(int, input().split())
	print(way(s, e))


import math

def sear(a):
	l = 0
	u = a
	c = -1
	while l <= u:
		if l == u:
			c = l
			break
		c = (l + u) // 2
		if c * (c + 1) // 2 >= a and c * (c - 1) // 2 < a:
			break
		if c * (c + 1) // 2 > a:
			u = c - 1
		else:
			l = c + 1
	return [c, a - c * (c - 1) // 2]

def powmod(a, b, p):
	a %= p
	if a == 0:
		return 0
	ret = 1
	while b > 0:
		if b & 1:
			ret *= a
			ret %= p
			b -= 1
		a *= a
		a %= p
		b //= 2
	return ret
mod = 10 ** 9 + 7
fa = [1]
for i in range(1, 10 ** 5 + 1):
	fa.append(fa[-1] * i % mod)

def inv(a, b):
	return powmod(a, b - 2, b)

def nck(n, k, p):
	return fa[n] * inv(fa[k], p) % p * inv(fa[n - k], p) % p
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = sear(n)
	b = sear(m)
	v = b[0] - a[0]
	i = b[1] - a[1]
	if v >= i >= 0 and v > 0:
		print(nck(v, i, mod))
	else:
		print(0)


import math

def pwm(a, b, m):
	a = a % m
	if a == 0:
		return 0
	p = 1
	while b > 0:
		if b % 2 == 1:
			p = p * a
			p = p % m
			b = b - 1
		a = a * a
		a = a % m
		b = b / 2
	return p

def fun2(a, m):
	return pwm(a, m - 2, m)

def fun(n, r, m):
	return lst[n] * fun2(lst[r], m) % m * fun2(lst[n - r], m) % m
lst = []
lst += [1]
lst += [1]
for i in range(2, 100001):
	lst += [lst[i - 1] * i % 1000000007]
t = int(input())
for i in range(t):
	m = 1000000007
	lst1 = input().split()
	x = int(lst1[0])
	y = int(lst1[1])
	k1 = int((math.sqrt(8 * x - 7) - 1) / 2)
	k2 = int((math.sqrt(8 * y - 7) - 1) / 2)
	k1n1 = int(k1 * (k1 + 1) / 2 + 1)
	k1n2 = k1n1 + k1
	k1d1 = x - k1n1
	k1d2 = k1n2 - x
	k2n1 = int(k2 * (k2 + 1) / 2 + 1)
	k2n2 = k2n1 + k2
	k2d1 = y - k2n1
	k2d2 = k2n2 - y
	if k2 > k1 and k2d1 >= k1d1 and (k2d2 >= k1d2):
		n = int(k2 - k1)
		r = y - (k2n1 + k1d1)
		print(fun(n, r, m))
	else:
		print(0)


from sys import stdin

def bezout(x, m):
	if m == 0:
		return (1, 0)
	(u, v) = bezout(m, x % m)
	return (v, u - x // m * v)

def inverse(x, m):
	return bezout(x, m)[0] % m

def binomial(fact, n, k, mod):
	if k < 0 or k > n:
		return 0
	return fact[n] * inverse(fact[k] * fact[n - k], mod) % mod

def solve():
	MOD = 10 ** 9 + 7
	results = []
	fact = [1]
	for i in range(1, 100000):
		fact.append(fact[-1] * i % MOD)
	for _ in range(int(stdin.readline().strip())):
		(s, e) = map(int, stdin.readline().rstrip().split())
		level1 = int((8 * s - 7) ** 0.5 - 1) // 2
		level2 = int((8 * e - 7) ** 0.5 - 1) // 2
		s_start = level1 * (level1 + 1) // 2 + 1
		s_end = s_start + level1
		e_start = level2 * (level2 + 1) // 2 + 1
		e_end = e_start + level2
		if level2 <= level1 or e - e_start < s - s_start or e_end - e < s_end - s:
			results.append(0)
			continue
		if e - e_start == s - s_start or e_end - e == s_end - s:
			results.append(1)
			continue
		tmp = e_start + s - s_start
		k = e - tmp
		results.append(binomial(fact, level2 - level1, k, MOD))
	print('\n'.join(map(str, results)))
solve()


import sys
import math

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
input = sys.stdin.readline
T = int(input())
level = lambda x: math.ceil((-1 + math.sqrt(1 + 8 * x)) / 2)
for _ in range(T):
	(S, E) = map(int, input().split())
	levelS = level(S)
	levelE = level(E)
	if levelS >= levelE:
		print(0)
	else:
		max_add = (levelS + 1 + levelE) * (levelE - levelS) // 2
		min_add = max_add - levelE + levelS
		inRange0 = E >= S + min_add and E <= S + max_add
		lefts = S + max_add - E
		currLevel = levelS + lefts
		print(0 if not inRange0 else ncr(levelE - levelS, currLevel - levelS, 1000000007))


import math

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

def last_ele(n):
	return int((n + 1) * n / 2)

def get_level(n):
	lev = -1
	ind = -1
	if n == 1:
		return 1
	st = 2
	end = math.ceil(math.sqrt(2 * n))
	while st <= end:
		lev = int((st + end) / 2)
		if last_ele(lev) >= n and last_ele(lev - 1) < n:
			break
		elif last_ele(lev) > n:
			end = lev - 1
		else:
			st = lev + 1
	return lev

def get_index(n):
	lev = -1
	ind = -1
	if n == 1:
		return 1
	st = 2
	end = math.ceil(math.sqrt(2 * n))
	while st <= end:
		lev = int((st + end) / 2)
		if last_ele(lev) >= n and last_ele(lev - 1) < n:
			break
		elif last_ele(lev) > n:
			end = lev - 1
		else:
			st = lev + 1
	ind = n - int((lev - 1) * lev / 2)
	return ind
for _ in range(int(input())):
	(s, e) = map(int, input().split())
	l1 = get_level(s)
	l2 = get_level(e)
	i1 = get_index(s)
	i2 = get_index(e)
	l = l2 - l1
	id = i2 - i1
	if l <= 0 or id < 0 or id > l:
		print('0')
	else:
		print(ncr(l, id, 10 ** 9 + 7))


import sys
MOD = 10 ** 9 + 7
FACT = [1]

def pyramid_moves(start, end):
	(sr, sc) = getcoords(start)
	(er, ec) = getcoords(end)
	return comb(er - sr, ec - sc)

def comb(a, b):
	if a < 0 or not 0 <= b <= a:
		return 0
	return fact(a) * pow(fact(b) * fact(a - b), MOD - 2, MOD) % MOD

def fact(a):
	while a >= len(FACT):
		FACT.append(FACT[-1] * len(FACT) % MOD)
	return FACT[a]

def getcoords(n):
	r = int((2 * n) ** 0.5)
	if r * (r + 1) // 2 >= n:
		r -= 1
	c = n - r * (r + 1) // 2 - 1
	return (r, c)
ncases = int(input())
for _ in range(ncases):
	print(pyramid_moves(*[int(s) for s in input().split()]))


from typing import DefaultDict
from math import sqrt
import math

def calculate(p, q):
	mod = 998244353
	expo = 0
	expo = mod - 2
	while expo:
		if expo & 1:
			p = p * q % mod
		q = q * q % mod
		expo >>= 1
	return p

def nCrModpDP(n, r, p):
	C = [0] * (n + 1)
	C[0] = 1
	for i in range(1, n + 1):
		j = min(i, r)
		while j > 0:
			C[j] = (C[j] + C[j - 1]) % p
			j -= 1
	return C[r]

def nCrModpLucas(n, r, p):
	if r == 0:
		return 1
	ni = int(n % p)
	ri = int(r % p)
	return nCrModpLucas(int(n / p), int(r / p), p) * nCrModpDP(ni, ri, p) % p

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

def isprime(n):
	prime_flag = 0
	if n > 1:
		for i in range(2, int(sqrt(n)) + 1):
			if n % i == 0:
				prime_flag = 1
				break
		if prime_flag == 0:
			return True
		else:
			return False
	else:
		return True

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def dict_ele_count(l):
	d = DefaultDict(lambda : 0)
	for ele in l:
		d[ele] += 1
	return d

def max_in_dict(d):
	maxi = 0
	for ele in d:
		if d[ele] > maxi:
			maxi = d[ele]
	return maxi

def element_count(s):
	l = []
	k = s[0]
	c = 0
	for ele in s:
		if ele == k:
			c += 1
		else:
			l.append([k, c])
			k = ele
			c = 1
	l.append([k, c])
	return l

def row(n):
	x = math.sqrt(8 * n + 1)
	x -= 1
	x /= 2
	if int(x) == x:
		return int(x)
	return int(x) + 1

def get_index(n):
	x = row(n)
	y = x * (x + 1) // 2
	return int(x + n - y)
for _ in range(int(input())):
	bool = True
	flag = True
	ans = 1
	mod = 10 ** 9 + 7
	(n, k) = map(int, input().split())
	if n == k:
		print(1)
	elif row(n) >= row(k) or get_index(n) > get_index(k):
		print(0)
	else:
		diag = get_index(k) - get_index(n)
		tot = row(k) - row(n)
		print(ncr(tot, diag, mod))


t = int(input())
mod = 10 ** 9 + 7

def binary_row(k):
	l = 1
	h = 45000
	while l <= h:
		mid = l + (h - l) // 2
		start = mid * (mid - 1) // 2 + 1
		end = start + mid - 1
		if start <= k <= end:
			return mid - 1
		elif k > end:
			l = mid + 1
		elif k < start:
			h = mid - 1
	return l - 1

def binomial_coeff(n, r):
	r = min(r, n - r)
	(num, den) = (1, 1)
	i = n
	for j in range(1, r + 1):
		num = num * i % mod
		den = den * j % mod
		i -= 1
	res = 1
	y = mod - 2
	x = den
	while y:
		if y & 1:
			res = res * x % mod
		y = y // 2
		x = x * x % mod
	ans = num * res % mod
	return ans
for i in range(t):
	(s, e) = map(int, input().split())
	if s == e:
		print(1)
	elif s < e:
		row_s = binary_row(s)
		row_e = binary_row(e)
		col_s = s - (row_s * (row_s + 1) // 2 + 1)
		col_e = e - (row_e * (row_e + 1) // 2 + 1)
		rel_row = row_e - row_s
		rel_col = col_e - col_s
		if rel_row != 0 and 0 <= rel_col <= rel_row:
			print(binomial_coeff(rel_row, rel_col) % (10 ** 9 + 7))
		else:
			print(0)
	else:
		print(0)


import math
mod7 = int(1000000000.0 + 7)

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

def le(level):
	return (level + 1) * level // 2

def get_values(n):
	level = -1
	index = -1
	if n == 1:
		return (1, 1)
	start = 2
	end = 1 + math.ceil(math.sqrt(2 * n))
	while start <= end:
		level = (start + end) // 2
		if le(level) >= n and le(level - 1) < n:
			break
		elif le(level) > n:
			end = level - 1
		else:
			start = level + 1
	index = n - level * (level - 1) // 2
	return (level, index)

def get_ans(s, e):
	res1 = get_values(s)
	res2 = get_values(e)
	s_level = res1[0]
	s_index = res1[1]
	e_level = res2[0]
	e_index = res2[1]
	lvl = e_level - s_level
	idx = e_index - s_index
	answer = -1
	if lvl <= 0 or idx < 0 or idx > lvl:
		answer = 0
	else:
		answer = ncr(lvl, idx, mod7)
	return answer % mod7
t = int(input())
while t:
	t -= 1
	(s, e) = map(int, input().split())
	ans = get_ans(s, e)
	print(ans)


import sys
input = sys.stdin.readline
fact = [1] * (10 ** 5 + 2)
tS = 0
tf = 1
mod = 10 ** 9 + 7
for i in range(1, 10 ** 5 + 2):
	fact[i] = fact[i - 1] * i % mod

def powmod(a, b, p):
	a %= p
	if a == 0:
		return 0
	product = 1
	while b > 0:
		if b % 2 == 1:
			product *= a
			product %= p
			b = b - 1
		a *= a
		a %= p
		b /= 2
	return product

def inv(a, p):
	return powmod(a, p - 2, p)

def nCk(n, k, p):
	return fact[n] * inv(fact[k], p) % p * inv(fact[n - k], p) % p
for _ in range(int(input())):
	(A, B) = map(int, input().split())
	if A > B:
		print(0)
		continue
	(a, b) = (0, 0)
	(ai, bi) = (0, 0)
	(i, k) = (1, 0)
	while i <= B:
		k += 1
		if i <= A:
			a = k
			ai = i
		i += k
	b = k
	bi = i - k
	if B - bi < A - ai:
		print(0)
		continue
	elif bi + b - 1 - B < ai + a - 1 - A:
		print(0)
		continue
	n = b - a
	r = B - (bi + A - ai)
	ans = nCk(n, r, mod)
	print(ans)


import math
N = 100001
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)

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

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

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

def Binomial(N, R, p):
	ans = fact[N] * factorialNumInverse[R] % p * factorialNumInverse[N - R] % p
	return ans

def level(n):
	n = n - 1
	b = math.sqrt(1 + 8 * n)
	b = b + 1
	return int(b // 2)

def pos(n, l):
	m = l * (l - 1)
	m = m // 2
	m = n - m
	return int(m)

def fa(n, c):
	a = math.factorial(n)
	b = math.factorial(c)
	d = math.factorial(n - c)
	e = a // b // d
	fa = 10 ** 9 + 7
	return e % fa

def pyr(a, b):
	return 1
	if a > b:
		return 0
	if a == b:
		return 1
p = 1000000007
InverseofNumber(p)
InverseofFactorial(p)
factorial(p)
n = int(input())
for i in range(n):
	x = list(input().split(' '))
	ac = int(x[0])
	bc = int(x[1])
	l1 = level(ac)
	p1 = pos(ac, l1)
	l2 = level(bc)
	p2 = pos(bc, l2)
	dp = p2 - p1
	dl = l2 - l1
	if dp > dl or dp < 0 or ac > bc:
		print(0)
	elif ac == bc or dp == dl or dp == 0:
		print(1)
	else:
		ji = 10 ** 9 + 7
		print(Binomial(dl, dp, ji))


from math import ceil, sqrt
M = 10 ** 9 + 7
fact = [1, 1]
for i in range(2, 10 ** 5 + 1):
	fact.append(fact[i - 1] * i % M)

def powmod(a, b, p):
	a %= p
	if a == 0:
		return 0
	product = 1
	while b > 0:
		if b % 2 == 1:
			product *= a
			product %= p
			b -= 1
		a *= a
		a %= p
		b /= 2
	return product

def inv(a, p):
	return powmod(a, p - 2, p)

def nCk(n, k, p):
	return fact[n] * inv(fact[k], p) % p * inv(fact[n - k], p) % p

def get_row_idx(n):
	level = ceil((sqrt(8 * n + 1) - 1) / 2)
	idx = n - level * (level - 1) // 2
	return (level, idx)
for _ in range(int(input())):
	(s, e) = map(int, input().split())
	(sl, si) = get_row_idx(s)
	(el, ei) = get_row_idx(e)
	L = el - sl
	K = ei - si
	if L <= 0 or K < 0 or K > L:
		print(0)
		continue
	print(nCk(L, K, M))


import sys
input = sys.stdin.readline
print = sys.stdout.write

def nCrModp(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
modn = 1000000007
t = int(input())
for tt in range(t):
	(s, e) = map(int, input().split())
	if e <= s:
		print('0\n')
		continue
	srow = int((s * 2) ** 0.5 + 0.5)
	erow = int((e * 2) ** 0.5 + 0.5)
	n = erow - srow
	if n <= 0:
		print('0\n')
		continue
	start = int(s + n / 2 * (srow + erow - 1))
	if e < start:
		print('0\n')
		continue
	end = int(s + n / 2 * (srow + 1 + erow))
	if e > end:
		print('0\n')
		continue
	r = e - start
	print(str(nCrModp(n, r, modn)) + '\n')


from bisect 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()
p = 10 ** 9 + 7
fac = [1]
inv = [pow(1, p - 2, p)]
for i in range(1, 10 ** 5):
	fac.append(fac[-1] * i % p)
	inv.append(pow(fac[-1], p - 2, p))
have = [1]
for i in range(10 ** 5):
	have.append(have[-1] + 1 + i)
while t:
	t -= 1
	(s, e) = ma()
	fi = bisect_right(have, s)
	se = bisect_right(have, e)
	if fi >= se:
		print(0)
	else:
		r1 = fi
		r2 = se
		c1 = s - have[fi - 1] + 1
		c2 = e - have[se - 1] + 1
		n = r2 - r1
		le = c1
		re = c1 + n
		if c2 < le or c2 > re:
			print(0)
		else:
			r = abs(c1 - c2)
			res = fac[n] * inv[r] * inv[n - r]
			print(res % p)


def row_column(num):
	n = 0
	while num > n * (n + 1) // 2:
		n = n + 1
	return (n - 1, num - n * (n - 1) // 2 - 1)

def power(x, y, m):
	if y == 0:
		return 1
	p = power(x, y // 2, m) % m
	p = p * p % m
	return p if y % 2 == 0 else x * p % m

def ncr(n, r, p, fact):
	num = fact[n]
	den = fact[n - r] * fact[r] % m
	return num * power(den, p - 2, p) % p
t = int(input())
fact = [0] * 100001
fact[0] = 1
m = 1000000007
for i in range(1, 100001):
	fact[i] = fact[i - 1] * i % m
for _ in range(t):
	(s, e) = map(int, input().split())
	(sr, sc) = row_column(s)
	(er, ec) = row_column(e)
	rr = er - sr
	rc = ec - sc
	if rr >= rc and rr >= 0 and (rc >= 0):
		ans = ncr(rr, rc, m, fact)
		print(ans)
	else:
		print(0)


from sys import stdin, setrecursionlimit
input = stdin.readline
setrecursionlimit(10 ** 6)
mod = 10 ** 9 + 7

def add(a, b):
	return (a % mod + b % mod) % mod

def sub(a, b):
	return (a - b + mod) % mod

def mul(a, b):
	return a % mod * (b % mod) % mod

def ncr(n, r):
	return mul(fact[n], mul(facti[n - r], facti[r]))

def div(a, b):
	return mul(a, pow(b, mod - 2, mod))
(fact, facti) = ([1], [1])
size = 2 * 10 ** 5 + 1
for i in range(1, size):
	fact.append(mul(fact[-1], i))
	facti.append(pow(fact[-1], mod - 2, mod))

def find(x):
	(l, h) = (0, x)
	while l <= h:
		mid = (l + h) // 2
		val = mid * (mid + 1) // 2
		if val < x:
			total = val
			row = mid + 1
			l = mid + 1
		else:
			h = mid - 1
	return [total, row]

def answer():
	(total1, row1) = find(s)
	(total2, row2) = find(e)
	(p1, p2) = (s - total1, e - total2)
	n = row2 - row1
	r = p2 - p1
	if r < 0 or r > n:
		return 0
	return ncr(n, r)
for T in range(int(input())):
	(s, e) = map(int, input().split())
	dp = dict()
	count = 0
	print(answer())


import sys

def input():
	return sys.stdin.readline().replace('\n', '').strip()
sys.setrecursionlimit(10 ** 9)

def _sum(i):
	return i * (i + 1) // 2

def search(el):
	if el == 1:
		return (1, 1)
	i = 0
	while True:
		i += 1
		if _sum(i) >= el:
			row = i
			start = _sum(i) - i + 1
			end = _sum(i)
			col = el - start + 1
			return (row, col)
mod = 10 ** 9 + 7
sz = 10 ** 5 + 1
fact = [1, 1]
for i in range(2, sz):
	fact.append(fact[-1] * i % mod)
inv_fact = []
for i in range(sz):
	inv_fact.append(pow(fact[i], mod - 2, mod))

def ncr(n, r):
	return fact[n] * inv_fact[n - r] % mod * inv_fact[r] % mod
for _ in range(int(input())):
	(s, e) = list(map(int, input().split()))
	start = search(s)
	end = search(e)
	if start[0] < end[0] and start[1] <= end[1] <= start[1] + end[0] - start[0]:
		down = end[0] - start[0]
		left = end[1] - start[1]
		print(ncr(down, left) % mod)
	else:
		print(0)


import math
P = 10 ** 9 + 7

def C(n, r):
	num = 1
	den = 1
	for j in range(1, r + 1):
		num = num * (n - j + 1) % P
		den = den * j % P
	pro = num * pow(den, P - 2, P)
	return pro % P

def g(n):
	m = math.floor((-1 + (1 + 8 * n) ** 0.5) * 0.5)
	z = n - m * (m + 1) // 2
	if z == 0:
		return (m - 1, m - 1)
	else:
		return (m, z - 1)

def f(s, e):
	(i_s, j_s) = g(s)
	(i_e, j_e) = g(e)
	if i_e < i_s:
		return 0
	else:
		p = i_e - i_s
		q = j_e - j_s
		if 0 <= q <= p:
			P1 = C(p, q)
			return P1
		else:
			return 0
t = int(input())
for i in range(0, t):
	(s, e) = map(int, input().split())
	print(f(s, e))