Chef is playing a game with his brother Chefu. He asked Chefu to choose a positive integer $N$, multiply it by a given integer $A$, then choose a divisor of $N$ (possibly $N$ itself) and add it to the product. Let's denote the resulting integer by $M$; more formally, $M = A \cdot N + d$, where $d$ is some divisor of $N$.
Chefu told Chef the value of $M$ and now, Chef should guess $N$. Help him find all values of $N$ which Chefu could have chosen.

-----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 $M$.

-----Output-----
For each test case, print two lines. The first line should contain a single integer $C$ denoting the number of possible values of $N$. The second line should contain $C$ space-separated integers denoting all possible values of $N$ in increasing order.
It is guaranteed that the sum of $C$ over all test cases does not exceed $10^7$.

-----Constraints-----
- $1 \le T \le 100$
- $2 \le M \le 10^{10}$
- $1 \le A < M$

-----Subtasks-----
Subtask #1 (50 points):
- $M \le 10^6$
Subtask #2 (50 points): original constraints

-----Example Input-----
3
3 35
5 50
4 65

-----Example Output-----
1
10
0

3
13 15 16

Difficulty: MEDIUM_HARD

Solutions:
from math import ceil

def solve():
	(a, m) = list(map(int, input().split()))
	n = ceil(m / a)
	all_vals = []
	while a * n + n >= m:
		if m - a * n > 0 and a * n + (m - a * n) * (n % (m - a * n) == 0) == m:
			all_vals.append(n)
		n -= 1
	print(len(all_vals))
	if len(all_vals) != 0:
		print(*all_vals[::-1])
for T in range(int(input())):
	solve()


from math import sqrt

def solve():
	(a, m) = list(map(int, input().split()))
	all_vals = []
	for i in range(1, int(sqrt(m)) + 1):
		if m % i == 0:
			if (m - i) % a == 0 and (m - i) // a % i == 0:
				all_vals.append((m - i) // a)
			i = m // i
			if i != m and (m - i) % a == 0 and ((m - i) // a % i == 0):
				all_vals.append((m - i) // a)
	print(len(all_vals))
	if len(all_vals) != 0:
		all_vals.sort()
		print(*all_vals)
for T in range(int(input())):
	solve()


import math

def search(l):
	a = l[0]
	n = l[1]
	g = []
	r = []
	e = []
	t = []
	z = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				g.append(i)
			else:
				g.append(i)
				g.append(int(n / i))
		i = i + 1
	g.sort()
	for i in g:
		k = int(n / i) - 1
		e.append(k)
	for j in e:
		if j % a == 0:
			p = int(j / a)
			ind = e.index(j)
			f = g[ind] * p
			z.append(f)
			t.append(p)
	z.sort()
	if len(z) == 1 and z[0] == 0:
		print('0')
	else:
		z.remove(0)
		print(len(z))
		print(*z, sep=' ')
t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	search(l)


def factorize(m: int) -> list:
	root = m ** 0.5
	i = 1
	factors = []
	while i < root + 1:
		if m % i == 0:
			factors.append((i, m // i))
			factors.append((m // i, i))
		i += 1
	return factors

def possible_n(factors: list, a: int) -> list:
	ns = []
	for (fi, fj) in factors:
		if fj == 1 or (fj - 1) % a != 0:
			continue
		n = fi * ((fj - 1) // a)
		ns.append(n)
	return sorted(set(ns))

def solve(a: int, m: int) -> list:
	factors = factorize(m)
	return possible_n(factors, a)

def main():
	t = int(input().strip())
	for _ in range(t):
		(a, m) = map(int, input().strip().split())
		ns = solve(a, m)
		print(len(ns))
		if ns:
			print(' '.join(map(str, ns)))
main()


def solve():
	(a, m) = list(map(int, input().split()))
	n = m // (a + 1)
	all_vals = []
	while a * n < m:
		if a * n + (m - a * n) * (n % (m - a * n) == 0) == m:
			all_vals.append(n)
		n += 1
	print(len(all_vals))
	if len(all_vals) != 0:
		print(*all_vals)
for T in range(int(input())):
	solve()


import math

def fun(a, m):
	q = int(math.sqrt(m))
	l = []
	for i in range(1, q + 1):
		if i * i != m:
			if m % i == 0:
				d = m // i
				if (d - 1) % a == 0:
					k = (d - 1) // a
					n = i * k
					l.append(n)
				if (i - 1) % a == 0:
					if i == 1:
						continue
					k = (i - 1) // a
					n = d * k
					l.append(n)
		elif (i - 1) % a == 0:
			k = (i - 1) // a
			n = d * k
			l.append(n)
	if len(l) == 0:
		print(0)
	else:
		l.sort()
		print(len(l))
		l = list(map(str, l))
		s = ' '
		s = s.join(l)
		print(s)
for _ in range(int(input())):
	(a, m) = list(map(int, input().split()))
	fun(a, m)