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

Starter code:

Solutions:
import math
def divisors(n):
 arr = []
 for i in range(1,1+int(math.ceil(math.sqrt(n)))):
  if n%i == 0:
   arr.append(i)
   arr.append(n//i)
 arr = list(sorted(set(arr)))
 return arr
try:
 t = int(input())
 while t:
  t -= 1
  a,m = map(int, input().split())
  divs = divisors(m)
  ans = []
  for d in divs:
   q = (m//d-1)/a
   if q%1 == 0 and q>0:
    ans.append((int(d*q)))
  ans.sort()
  print(len(ans))
  for i in ans:
   print(i, end = ' ')
  print()
except:
 pass

import math
def divisors(n):
 arr = []
 for i in range(1,1+int(math.ceil(math.sqrt(n)))):
  if n%i == 0:
   arr.append(i)
   arr.append(n//i)
 arr = list(sorted(set(arr)))
 return arr
try:
 t = int(input())
 while t:
  t -= 1
  a,m = map(int, input().split())
  divs = divisors(m)
  ans = []
  for d in divs:
   q = (m//d-1)/a
   if q%1 == 0 and q>0:
    ans.append((int(d*q)))
  ans.sort()
  print(len(ans))
  for i in ans:
   print(i, end = ' ')
  print()
except:
 pass

T = int(input())
import math
for i in range(T):
 list = []
 A,M = input().split()
 A = int(A)
 M = int(M)
 L1 = M//A
 L2 = math.ceil(M/(A+1))
 while L2 <= L1 :
  N = L2
  if M - N*A !=0 and N%(M - N*A) == 0 :
   list.append(L2)
  L2 += 1

 print(len(list))
 if len(list) > 0:
  for j in range(len(list)-1):
   print(list[j],end=" ")
  print(list[len(list)-1])
 else:
  print(" ")


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


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


# cook your dish here
from math import sqrt
def solve():
 a,m=list(map(int,input().split()))
 n=m//(a+1)

 all_vals=[]
 
 while(a*n<m or (a>=int(sqrt(m)) and n<=sqrt(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()
 


# cook your dish here
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()
 


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


# cook your dish here
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

for _ in range(int(input())):
 a,m=list(map(int, input().split()))
 f={1}
 for i in range(2, int(math.sqrt(m))+1):
  if m%i==0:
   f.add(i)
   f.add(m//i)
 
 total=0
 l=[]
 for i in f:
  p=m-i
  if p%a==0:
   q=p//a 
   if q%i==0:
    l.append(q)
    total+=1 
    
 print(total)
 if total>0:
  l.sort()
  print(*l, end=' ')
  print('')
  
 else:
  print(' ')

# -*- coding: utf-8 -*-
"""
Created on Wed Oct  7 10:50:29 2020

@author: Vineet
"""


from math import sqrt

t=int(input())

while(t>0):
 a,m = [int(x) for x in input().split()]
 div=[]
 n=[]
 for i in range(1,int(sqrt(m))+1):
  if m%i==0:
   if m//i==i:
    div.append(i)
   else:
    div.append(i)
    div.append(m//i)
 div.sort()
 div=div[:-1]
 
 for i in div:
  if ((m//i)-1)%a==0:
   n.append(i*(((m//i)-1)//a))
 s=set(n)
 n=list(s)
 n.sort()
 print(len(n))
 for i in n:
  print(i,end=' ')
 print()

 t-=1

# -*- coding: utf-8 -*-
"""
Created on Wed Oct  7 10:50:29 2020

@author: Vineet
"""


from math import sqrt

t=int(input())

while(t>0):
 a,m = [int(x) for x in input().split()]
 div=[]
 n=[]
 for i in range(1,int(sqrt(m))+1):
  if m%i==0:
   if m//i==i:
    div.append(i)
   else:
    div.append(i)
    div.append(m//i)
 div.sort()
 div=div[:-1]
 
 for i in div:
  if ((m//i)-1)%a==0:
   n.append(i*(((m//i)-1)//a))
 s=set(n)
 n=list(s)
 n.sort()
 print(len(n))
 for i in n:
  print(i,end=' ')
 print()

 t-=1

# cook your dish here
def getdiv(m):
 i=1
 res=[]
 while(i*i<=m):
  if(m%i==0):
   res.append(i)
   if(m//i!=i):
    res.append(m//i)
  i+=1
 return res

test=int(input())
for _ in range(test):
 a,m=map(int,input().split())
 div=getdiv(m)
 res=[]
 for i in div:
  n=(m-i)/a
  if(n>=i and n%1==0 and n%i==0):
   res.append(int(n))
 res.sort()
 print(len(res))
 for i in res:
  print(i,end=' ')
 print('')

# cook your dish here
# code by RAJ BHAVSAR

def getdiv(m):
 i = 1
 res = []
 while(i*i <= m):
  if(m%i == 0):
   res.append(i)
   if(m//i != i):
    res.append(m//i)
  i += 1
 return res

for _ in range(int(input())):
 a,m = map(int,input().split())
 div = getdiv(m)
 res = []
 for i in div:
  n = (m-i)/a
  if(n>=i and n%1 == 0 and n%i == 0):
   res.append(int(n))
 res.sort()
 print(len(res))
 for i in res:
  print(i,end=' ')
 print('')

t=int(input())
for i in range(t):
 am=input().split()
 a=int(am[0])
 m=int(am[1])
 l=list()
 c=0
 indx=m//a
 for i in range(indx,0,-1):
  diff=m-i*a
  if(diff>i):
   break
  if(diff!=0):
   if(i%diff==0):
    c+=1
    l.append(i)
 l.sort()
 res=str()
 for i in range(len(l)):
  res=res+str(l[i])+" "
 res.rstrip()
 print(c)
 print(res)


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)
 

import math
t = int(input())
while t>0:
 t -= 1
 # n = int(input())
 a, m = list(map(int, input().split()))
 d = 1
 ans = set()
 limit = int(math.sqrt(m)+1)
 while d<limit+1:
  if m%d == 0:
   num = m//d-1
   if num%a == 0:
    ans.add((num//a)*d)
   d2 = m//d
   num = m//d2-1
   if num > 0 and num%a == 0:
    ans.add((num//a)*d2)
  d += 1
 print(len(ans))
 print(*sorted(ans))






# cook your dish here
t=int(input())
for _ in range(t):
 d=[]
 jj=0
 a,m=list(map(int,input().split()))
 p=m//(a+1)
 q=m//a
 for i in range(p,q+1):
  if i!=m/a:
   
   if i%(m-a*i)==0:
    d.append(i)
  #jj=jj+1    
 print(len(d))
 #print(d)
 d.sort()
 # print(jj)
 for u in d:
  print(u,end=" ")
 print("\n",end="") 
  


import sys
import math
from collections import defaultdict,Counter

# input=sys.stdin.readline
# def print(x):
#     sys.stdout.write(str(x)+"\n")

# sys.stdout=open("CP3/output.txt",'w')
# sys.stdin=open("CP3/input.txt",'r')

# m=pow(10,9)+7
t=int(input())
for i in range(t):
 a,m=map(int,input().split())
 r=(m-1)//a
 # print(r)
 l=[]
 for j in range(1,r+1):
  if m%(a*j+1)==0:
   d=m//(a*j+1)
   l.append(d*j)
 print(len(l))
 print(*l)

# cook your dish here
import math
def Divisors(n):
 l=[]
 for i in range(1,int(math.sqrt(n))+1):
  if n%i==0:
   if n/i==i:
    l.append(i)
   else:
    l.append(n//i)
    l.append(i)
 return l
   
from sys import stdin,stdout
for _ in range(int(input())):
 a,m=list(map(int,input().split()))
 div=Divisors(m)
 #print(div)
 ans=set()
 for i in div:
  if ((m//i)-1)%a==0:
   ans.add((((m//i)-1)//a)*i)
 ans=list(ans)[1:]
 ans.sort()
 print(len(ans))
 print(*ans)
 


import sys
def input(): return sys.stdin.readline().strip()

t = int(input())
while t:
 t -= 1
 a, m = map(int, input().split())
 possible = []
 for i in range(2, int(m**0.5)+1):
  if not m%i:
   d = m//i
   if not (m-d)%(a*d):
    possible.append((m-d)//a)
   d = m//d
   if not (m-d)%(a*d):
    possible.append((m-d)//a)
 if not(m-1)%a:
  possible.append((m-1)//a)
  
 possible.sort()
 print(len(possible))
 for i in possible:
  print(i, end = " ")
 print()


# cook your dish here
t = int(input())
while t>0:
 a,m = list(map(int,input().split()))
 l = m//a
 arr = []
 for i in range(l,0,-1):
  if m-i*a>i:
   break
  if m-a*i==0:
   continue
  elif i%(m-a*i)==0:
   arr.append(i)
 print(len(arr))
 arr = arr[::-1]
 print(" ".join(map(str,arr)))
 t=t-1