from functools import lru_cache @lru_cache(maxsize = None) def prim(p): if p in {2, 3}: return p-1 Cand = [True for _ in range(p)] Cand[0], Cand[1] = False, False for i in range(2, p): if Cand[i]: Cand[i] = False ct, exp = 1, i while exp != 1: exp *= i exp %= p Cand[exp] = False ct += 1 if ct == p-1: return i for _ in range(int(input())): v, x = map(int, input().split()) q = v*x+1 g = prim(q) h = pow(g, v, q) print(*sorted([pow(h, i, q) for i in range(x)]))