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()) g = prim(x*v+1) h = pow(g, v, x*v+1) print(*[pow(h, i, x*v+1) for i in range(x)])