t = int(input()) for _ in range(t): v,x = map(int,input().split()) mod = v*x+1 for i in range(1,mod): if pow(i,x,mod) != 1: continue s = set() now = i for j in range(x): s.add(now) now *= i now %= mod if len(s) == x: ans = sorted(list(s)) print(*ans) break