def primitive_root(m): if m == 2: return 1 if m == 167772161: return 3 if m == 469762049: return 3 if m == 754974721: return 11 if m == 998244353: return 3 Divs = [2] x = (m-1)//2 while x%2 == 0: x //= 2 i = 3 while i*i <= x: if not x%i: Divs.append(i) while not x%i: x //= i i += 2 if x > 1: Divs.append(x) g = 2 while True: if all(pow(g, (m-1)//div, m) != 1 for div in Divs): return g g += 1 for _ in range(int(input())): v, x = map(int, input().split()) q = v*x+1 g = primitiv_root(q) h = pow(g, v, q) print(*sorted([pow(h, i, q) for i in range(x)]))