def prime_factors(N): #素因数のリスト factors = [] if N&1==0: factors = [2] while N%2 == 0: N //= 2 else: factorization = [] M = int(N**0.5)+1 for i in range(3,M,2): if N%i==0: while N%i == 0: N //= i factors.append(i) if N!= 1: factors.append(N) assert N != 0, "zero" return factors def solve(v,x): p = v*x+1 ps = prime_factors(v)+prime_factors(x) r = 1 for r in range(2,p): for pp in ps: if pow(r,v*x//pp,p) == 1: break else: break a = [pow(r,i*v,p) for i in range(x)] return sorted(a) T = int(input()) for _ in range(T): v,x = map(int,input().split()) print(*solve(v,x))