def p(m): if m==2: return 1 D,x=[2],(m-1)//2 while x&1: x//=2 i=3 while i*i<=x: if not x%i: D.append(i) while not x%i: x//=i i+=2 if x>1: D.append(x) g=2 while True: if all(pow(g,(m-1)//d,m)!= 1for d in D): return g g+=1 for _ in range(int(input())): v,x=map(int,input().split()) q=v*x+1 h=pow(p(q),v,q) print(*sorted([pow(h,i,q) for i in range(x)]))