import sys,os,io input = sys.stdin.readline #input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from random import * T = int(input()) for t in range(T): v, x = map(int, input().split()) p = v*x+1 while True: i = randint(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)