Ram and Shyam are sitting next to each other, hoping to cheat on an exam. However, the examination board has prepared $p$ different sets of questions (numbered $0$ through $p-1$), which will be distributed to the students in the following way:
- The students are assigned roll numbers — pairwise distinct positive integers.
- If a student's roll number is $r$, this student gets the $((r-1)\%p)$-th set of questions.
Obviously, Ram and Shyam can cheat only if they get the same set of questions.
You are given the roll numbers of Ram and Shyam: $A$ and $B$ respectively. Find the number of values of $p$ for which they can cheat, or determine that there is an infinite number of such values.

-----Input-----
- The first line of the input contains a single integer $T$ denoting 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 $A$ and $B$.

-----Output-----
For each test case, print a single line — the number of values of $p$ for which Ram and Shyam can cheat, or $-1$ if there is an infinite number of such values.

-----Constraints-----
- $1 \le T \le 100$
- $1 \le A, B \le 10^8$

-----Example Input-----
1
2 6

-----Example Output-----
3

-----Explanation-----
Example case 1: They can cheat for $p = 1$, $p = 2$ or $p = 4$.

Difficulty: MEDIUM_HARD

Solutions:
import math
t = int(input())
while t > 0:
	t -= 1
	(a, b) = input().split()
	a = int(a) - 1
	b = int(b) - 1
	c = abs(a - b)
	ans = 0
	i = 1
	while i <= math.sqrt(c):
		if c % i == 0:
			if c / i == i:
				ans += 1
			else:
				ans += 2
		i += 1
	if a == b:
		print(-1)
	else:
		print(ans)


import math
t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	count = 0
	n = abs(a - b)
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			count += 1
			if n / i != i:
				count += 1
	print(count)
	t -= 1


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(-1)
		continue
	diff = abs(a - b)
	fact = set()
	for i in range(1, int(math.sqrt(diff)) + 1):
		if diff % i == 0:
			fact.add(i)
			fact.add(diff // i)
	print(len(fact))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	diff = abs(a - b)
	count = 0
	for i in range(1, int(diff ** 0.5) + 1):
		if diff % i == 0:
			count += 1
			if diff / i != i:
				count += 1
	print(count)


import math
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	(a, b) = (a - 1, b - 1)
	c = 0
	t = abs(a - b)
	if t == 0:
		print(-1)
	else:
		c = 0
		i = 1
		while i <= math.sqrt(t):
			if t % i == 0:
				if t // i == i:
					c = c + 1
					i = i + 1
					continue
				c = c + 2
			i += 1
		print(c)


T = int(input())
result = []

def number(factor):
	count = 0
	if int(factor ** 0.5) == factor ** 0.5:
		count -= 1
	for i in range(1, int(factor ** 0.5) + 1):
		if factor % i == 0:
			count += 2
	return count
for i in range(T):
	data = input().split()
	count = 0
	factor = abs(int(data[0]) - int(data[1]))
	result.append(number(factor))
for i in result:
	print(i)


import math
T = int(input())
for _ in range(T):
	(r1, r2) = map(int, input().split(' '))
	n = abs(r1 - r2)
	count = 0
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n / i == i:
				count += 1
			else:
				count += 2
	print(count)


import math
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	diff = abs(a - b)
	c = 0
	for i in range(1, int(math.sqrt(diff)) + 1):
		if diff % i == 0:
			c += 1
			if diff // i != i:
				c += 1
	print(c)


def EC(c):
	r = 0
	for i in range(1, int(c ** 0.5) + 1):
		if c % i == 0:
			r += 1 + (i * i != c)
	return r
for i in range(int(input())):
	(x, y) = sorted(map(int, input().split()))
	print(EC(y - x))


from math import sqrt, ceil
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(-1)
		continue
	x = abs(a - b)
	ans = 0
	for i in range(1, int(sqrt(x)) + 1):
		if x % i == 0:
			ans += 1
			if x / i != i:
				ans += 1
	print(ans)


import math
t = int(input())
while t > 0:
	(a, b) = map(int, input().strip().split())
	d = abs(a - b)
	if d == 0:
		print(-1)
	else:
		(c, i) = (0, 1)
		while i <= math.sqrt(d):
			if d % i == 0:
				if d / i == i:
					c += 1
				else:
					c += 2
			i += 1
		print(c)
	t -= 1


import math
for _ in range(int(input())):
	(l, r) = map(int, input().split(' '))
	c = 0
	n = abs(l - r)
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n / i == i:
				c += 1
			else:
				c += 2
	print(c)


import math

def counter(n):
	i = 1
	c = 0
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				c += 1
			else:
				c += 2
		i += 1
	if c == 0:
		return -1
	return c
for i in range(int(input())):
	(a, b) = map(int, input().split())
	print(counter(abs(a - b)))


def divisors(num):
	ans = []
	for i in range(1, int(num ** 0.5) + 1):
		if num % i == 0:
			ans.append(i)
			ans.append(num // i)
	return len(set(ans))
for t in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(-1)
	else:
		print(divisors(abs(a - b)))


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)

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

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

def lint():
	return [int(x) for x in stdin.readline().split()]

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

def grid(r, c):
	return [lint() for i in range(r)]

def debug(*args, c=6):
	print('\x1b[3{}m'.format(c), *args, '\x1b[0m', file=stderr)
from math import log2, sqrt

def f(n):
	i = 1
	se = set()
	while i * i <= n:
		if n % i == 0:
			if n / i == i:
				se.add(i)
			else:
				se.add(i)
				se.add(n / i)
		i += 1
	return se

def main():
	for _ in range(I()):
		(a, b) = tup()
		if a == b:
			print(-1)
		else:
			print(len(f(abs(a - b))))
main()


t = int(input())

def fact(p):
	count = 0
	i = 1
	while i * i <= p:
		if p % i == 0:
			if p / i == i:
				count += 1
			else:
				count += 2
		i = i + 1
	return count
for _ in range(t):
	(a, b) = map(int, input().split())
	p = abs(a - b)
	if p == 0:
		print('-1')
	else:
		print(fact(p))


for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	n = abs(a - b)
	c = 0
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if n / i == i:
				c += 1
			else:
				c += 2
	print(c)


import math
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	diff = abs(a - b)
	count = 0
	for i in range(1, int(math.sqrt(diff)) + 1):
		if diff % i == 0:
			if i == diff // i:
				count += 1
			else:
				count += 2
	print(count)


mod = 1000000007
read_int = lambda : int(input().strip())
read_str = lambda : input().strip()
read_str_arr = lambda : input().strip().split()
read_int_arr = lambda : [int(x) for x in input().strip().split()]

def solve():
	(a, b) = read_int_arr()
	if a == b:
		print(-1)
		return
	n = abs(a - b)
	ans = 0
	i = 1
	while i * i <= n:
		if n % i == 0:
			ans += 1
			if i != n / i:
				ans += 1
		i += 1
	print(ans)
for _ in range(int(input())):
	solve()


import math as m
t = int(input())
while t:
	t -= 1
	(a, b) = map(int, input().split())
	count = 0
	d = abs(a - b)
	if d == 0:
		print(-1)
	else:
		for i in range(1, int(m.sqrt(d)) + 1):
			if d % i == 0:
				if d / i == i:
					count += 1
				else:
					count += 2
	print(count)


def printDivisors(n):
	i = 1
	count = 0
	while i <= n ** 0.5:
		if n % i == 0:
			if n / i == i:
				count += 1
			else:
				count += 2
		i = i + 1
	return count
t = int(input())
while t > 0:
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(-1)
	else:
		count = printDivisors(abs(a - b))
		print(count)
	t = t - 1


mem = {}

def soln(a, b):
	diff = abs(a - b)
	if diff in mem:
		return mem[diff]
	count = 0
	for i in range(1, int(diff ** 0.5) + 1):
		if diff % i == 0:
			if diff / i == i:
				count += 1
			else:
				count += 2
	mem[diff] = count
	return count
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(soln(a, b))


import math
t = int(input())
while t:
	t -= 1
	(a, b) = map(int, input().split())
	x = []
	if a == b:
		print(-1)
	else:
		c = abs(a - b)
		ct1 = 0
		i = 1
		while i <= math.sqrt(c):
			if c % i == 0:
				if c / i == i:
					ct1 += 1
				else:
					ct1 += 2
			i = i + 1
		print(ct1)


from math import sqrt
t = int(input())
while t:
	(a, b) = map(int, input().split())
	count = 0
	x = max(b, a) - min(a, b)
	for i in range(1, int(sqrt(x)) + 1):
		if not x % i:
			y = x // i
			if i == y:
				count += 1
			else:
				count += 2
	print(count)
	t -= 1


t = int(input())
import math
for i in range(t):
	(a, b) = list(map(int, input().split()))
	x = abs(a - b)
	c = 0
	for i in range(1, int(math.sqrt(x)) + 1):
		if x % i == 0:
			c += 2
	if int(math.sqrt(x)) == math.sqrt(x):
		c -= 1
	print(c)


import math

def divisors(n):
	i = 1
	count = 0
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				count += 1
			else:
				count += 2
		i = i + 1
	return count
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	p = abs(a - b)
	if p == 0:
		print(-1)
	else:
		print(divisors(p))


import math
c = int(input())
for i in range(c):
	(a, b) = list(map(int, input().split()))
	e = a - b
	d = abs(e)
	dd = int(math.sqrt(d))
	z = 0
	for j in range(1, dd + 1):
		if d % j == 0:
			z += 1
			if d / j != j:
				z += 1
	if z == 0:
		print('-1')
	else:
		print(z)


t = int(input())
for i in range(t):
	c = 0
	(a, b) = map(int, input().split())
	if a == b:
		print(-1)
	else:
		for i in range(1, int(pow(abs(a - b), 0.5)) + 1):
			if (a - b) % i == 0:
				if i * i == abs(a - b):
					c += 1
				else:
					c += 2
	print(c)


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	k = abs(m - n)
	c = 0
	i = 1
	while i <= int(k ** (1 / 2)):
		if k % i == 0:
			if k // i == i:
				c += 1
			else:
				c += 2
		i += 1
	print(c)
	t = t - 1


for t in range(int(input())):
	(a, b) = list(map(int, input().split()))
	d = abs(a - b)
	if d > 1:
		k = 2
		c = d
		d **= 0.5
		for i in range(2, int(d) + 1):
			if c % i == 0:
				k += 2
				if i == d:
					k -= 1
	else:
		k = 1
	print(k)


try:
	import math
	t = int(input())
	for i in range(0, t):
		(a, b) = map(int, input().split(' '))
		if a == b:
			print(-1)
		else:
			k = abs(a - b)
			c = 0
			i = 1
			while i <= math.sqrt(k):
				if k % i == 0:
					if k / i == i:
						c += 1
					else:
						c += 2
				i += 1
			print(c)
except:
	pass


from math import sqrt
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	c = 0
	e = abs(a - b)
	for i in range(1, int(sqrt(e)) + 1):
		if e % i == 0:
			c += 1
			if e / i != i:
				c += 1
	if c == 0:
		print(-1)
	else:
		print(c)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = int(math.sqrt(abs(a - b)))
	c1 = 0
	for i in range(1, c + 1):
		if abs(a - b) % i == 0:
			c1 += 1
	if abs(a - b) == c ** 2:
		print(2 * c1 - 1)
	else:
		print(c1 << 1)


for z in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	if a == b:
		print(-1)
	else:
		p = abs(a - b)
		c = 0
		r = int(p ** 0.5)
		for i in range(1, 1 + r):
			if p % i == 0:
				c += 2
		if r * r == p:
			c -= 1
		print(c)


for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	num = max(a, b) - min(a, b)
	if num == 0:
		print(-1)
	else:
		i = 1
		count = 0
		while i * i <= num:
			if num % i == 0:
				if i * i == num:
					count += 1
				else:
					count += 2
			i += 1
		print(count)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	n = abs(a - b)
	if n == 0:
		print(-1)
	elif n == 1:
		print(1)
	else:
		ans = 2
		p = int(math.sqrt(n))
		for i in range(2, p + 1):
			if n % i == 0:
				if i != n // i:
					ans += 2
				else:
					ans += 1
		print(ans)


def divisors(x):
	f = 0
	for i in range(1, int(x ** 0.5) + 1):
		if x % i == 0:
			if x // i == i:
				f += 1
			else:
				f += 2
	return f
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(divisors(abs(a - b)))


import math
for r in range(int(input())):
	(a, b) = map(int, input().split())
	v = []
	z = abs(a - b)
	c = 0
	n = z
	e = int(math.sqrt(n))
	for i in range(1, e + 1):
		if n % i == 0:
			if n / i == i:
				c = c + 1
			else:
				c = c + 2
	print(c)


from math import sqrt

def fact(n):
	(i, c) = (1, 0)
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if n / i == i:
				c += 1
			else:
				c += 2
	return c
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	q = abs(a - b)
	if q == 0:
		print(-1)
	else:
		factors = fact(q)
		print(factors)


for test in range(0, int(input())):
	(A, B) = map(int, input().split())
	diff = abs(A - B)
	count = 0
	if not A ^ B:
		print(-1)
	else:
		for i in range(1, int(diff ** (1 / 2)) + 1):
			if diff % i == 0:
				if diff / i == i:
					count += 1
				else:
					count += 2
		print(count)


def divs(x):
	r = 0
	for i in range(1, int(x ** 0.5) + 1):
		if x % i == 0:
			r += 1 + (i * i != x)
	return r
for _ in range(int(input())):
	(a, b) = sorted(map(int, input().split()))
	print(divs(b - a))


import math
T = int(input())
for _ in range(T):
	(A, B) = map(int, input().split())
	c = 0
	Y = abs(B - A)
	for i in range(1, int(math.sqrt(Y) + 1)):
		if Y % i == 0:
			if Y // i != i:
				c += 2
			else:
				c += 1
	print(c)


tc = int(input())
for _ in range(tc):
	(a, b) = map(int, input().split())
	if a == b:
		print(-1)
	else:
		cnt = 0
		g = abs(a - b)
		for i in range(1, int(g ** 0.5) + 1):
			if g % i == 0:
				if g / i == i:
					cnt += 1
				else:
					cnt += 2
		print(cnt)


t = int(input())
for you in range(t):
	l = input().split()
	a = int(l[0])
	b = int(l[1])
	if a == b:
		print(-1)
		continue
	f = 0
	val = abs(a - b)
	curr = 1
	while curr * curr <= val:
		if val % curr == 0:
			f += 1
			if curr * curr != val:
				f += 1
		curr += 1
	print(f)


from math import *
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	c = abs(b - a)
	count = 0
	for j in range(1, int(sqrt(c) + 1)):
		if c % j == 0:
			if c / j == j:
				count += 1
			else:
				count += 2
	print(count)


import math
for i in range(int(input())):
	(a, b) = map(int, input().strip().split())
	c = abs(a - b)
	ans = 0
	i = 1
	while i <= math.sqrt(c):
		if c % i == 0:
			if c / i == i:
				ans += 1
			else:
				ans += 2
		i += 1
	if a == b:
		print(-1)
	else:
		print(ans)


def solve(x):
	r = 0
	for j in range(1, int(x ** 0.5) + 1):
		s = x % j == 0
		r += s
		if j * j != x:
			r += s
	return r
t = int(input())
for i in range(t):
	(a, b) = sorted(map(int, input().split()))
	print(solve(b - a))


for nt in range(int(input())):
	(a, b) = map(int, input().split())
	n = abs(a - b)
	cnt = 0
	for i in range(1, int(n ** (1 / 2)) + 1):
		if n % i == 0:
			if n / i == i:
				cnt += 1
			else:
				cnt += 2
	print(cnt)


def ct(n):
	c = 0
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if n / i != i:
				c += 1
			c += 1
	return c
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = abs(b - a)
	print(ct(c))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print('-1')
	else:
		count = 0
		val = abs(a - b)
		for i in range(1, int(val ** 0.5) + 1):
			if val % i == 0:
				if val / i == i:
					count += 1
				else:
					count += 2
		print(count)


from math import sqrt
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	n = abs(a - b)
	(count, i) = (0, 1)
	while i <= sqrt(n):
		if n % i == 0:
			if n / i == i:
				count += 1
			else:
				count += 2
		i += 1
	print(count)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	s = abs(a - b)
	ctr = 0
	i = 1
	while i * i <= s:
		if s % i == 0:
			if s // i == i:
				ctr += 1
			else:
				ctr += 2
		i += 1
	print(ctr)


from math import sqrt

def get_factors(n):
	f = 0
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			f += 1
			if i != n // i:
				f += 1
	return f
T = int(input())
ans = []
for _ in range(T):
	(A, B) = [int(i) for i in input().split()]
	x = A - 1
	y = B - 1
	ans.append(get_factors(abs(x - y)))
for i in ans:
	print(i)


from sys import stdin, stdout
import math
from collections import Counter
import functools
import time

def tr():
	return range(int(line()))

def sm():
	return map(int, line().split())

def ln():
	return list(sm())

def nl():
	return int(line())

def ssm():
	return map(str, line().split())

def line():
	return stdin.readline().rstrip()

def b(x):
	return bin(x).replace('0b', '')

def o(x):
	if type(x) != type(''):
		x = str(x)
	stdout.write(x + '\n')

def osp(x):
	if type(x) != type(''):
		x = str(x)
	stdout.write(x + ' ')

def ol(x):
	stdout.write(' '.join(map(str, x)) + '\n')

def main():
	for _ in tr():
		(a, b) = sm()
		if a == b:
			print(-1)
			continue
		count = 0
		check = abs(a - b)
		till = int(math.sqrt(check)) + 1
		for p in range(1, till):
			if check % p == 0:
				count += 2
				if check / p == p:
					count -= 1
		print(count)
main()


import math
for _ in range(int(input())):
	(A, B) = list(map(int, input().split()))
	if A == B:
		print(-1)
		continue
	x = abs(A - B)
	factors = set()
	for i in range(1, int(math.sqrt(x)) + 1):
		if x % i == 0:
			factors.add(i)
			factors.add(x // i)
	print(len(factors))


import math

def countDivisors(n):
	cnt = 0
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n / i == i:
				cnt = cnt + 1
			else:
				cnt = cnt + 2
	return cnt
for _ in range(int(input())):
	(A, B) = map(int, input().rstrip().split())
	diff = abs(A - B)
	z = countDivisors(diff)
	if z == 0:
		prit(-1)
	else:
		print(z)


import math
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	diff = abs(a - b)
	if diff == 0:
		print(-1)
	elif diff == 1:
		print(1)
	else:
		ans = 2
		s = int(math.sqrt(diff))
		for i in range(2, s + 1):
			if diff % i == 0:
				if i != diff // i:
					ans = ans + 2
				else:
					ans = ans + 1
		print(ans)


import math

def countDivisors(n):
	cnt = 0
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n / i == i:
				cnt = cnt + 1
			else:
				cnt = cnt + 2
	return cnt
for ttt in range(int(input())):
	(a, b) = map(int, input().split())
	print(countDivisors(abs(b - a)))


import math
for _ in range(int(input())):
	(a, b) = sorted(map(int, input().split()))
	n = b - a
	poss = 0
	i = 1
	while i <= math.sqrt(n) // 1:
		if n % i == 0:
			if n / i == i:
				poss += 1
			else:
				poss += 2
		i = i + 1
	print(poss)


import math

def check(n):
	cnt = 0
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			cnt += 1
			if n // i != i:
				cnt += 1
	return cnt
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	x = abs(a - b)
	print(check(x))


from math import sqrt
for i in range(int(input())):
	(a, b) = map(int, input().split())
	c = abs(a - b)
	d = 0
	if c == 0:
		print(-1)
	else:
		for i in range(1, int(sqrt(c)) + 1):
			if c % i == 0:
				d += 1
				if c // i != i:
					d += 1
		print(d)


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

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())
for _ in range(ii()):
	(a, b) = mi()
	d = abs(a - b)
	if d == 0:
		print(-1)
	else:
		cn = 0
		i = 1
		while i * i <= d:
			if d % i == 0:
				if d // i == i:
					cn += 1
				else:
					cn += 2
			i += 1
		print(cn)


import math

def divs(n):
	cnt = 0
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n / i == i:
				cnt = cnt + 1
			else:
				cnt = cnt + 2
	return cnt
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	print(divs(abs(n - m)))


def solve():
	(n, m) = list(map(int, input().split()))
	diff = abs(n - m)
	cnt = 0
	for j in range(1, int(diff ** 0.5 + 1)):
		if diff % j == 0:
			if diff / j == j:
				cnt += 1
			else:
				cnt += 2
	print(cnt)
t = int(input())
while t != 0:
	solve()
	t -= 1


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	z = abs(a - b)
	c = 0
	for i in range(1, int(z ** (1 / 2)) + 1):
		if z % i == 0:
			if z / i == i:
				c += 1
			else:
				c += 2
	print(c)


import math
test_case = int(input())
for test in range(test_case):
	(a, b) = map(int, input().split())
	n = abs(a - b)
	cnt = 0
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n / i == i:
				cnt = cnt + 1
			else:
				cnt = cnt + 2
	if cnt == 0:
		print(-1)
	else:
		print(cnt)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	n = a - b
	p = 0
	if n < 0:
		n *= -1
	if n == 1:
		print(1)
	else:
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				if n / i == i:
					p += 1
				else:
					p += 2
		print(p)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	c = abs(b - a)
	cnt = 0
	for j in range(1, int(c ** (1 / 2)) + 1):
		if c % j == 0:
			if c // j == j:
				cnt += 1
			else:
				cnt += 2
	print(cnt)