import sys,os,io input = sys.stdin.readline #input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline T = int(input()) for t in range(T): v, x = map(int, input().split()) p = v*x+1 for i in range(1,p+1): if pow(i,x,p)==1: s = set() a = i for _ in range(x): s.add(a) a *= i a %= p if len(s)==x: ans = sorted(list(s)) break print(*ans)