## https://yukicoder.me/problems/no/1409 def solve(V, X): array = [] for p in range(1, V * X +1): a = pow(p, X, V * X + 1) if a == 1: array.append(p) if len(array) == X: break return " ".join(map(str, array)) def main(): T = int(input()) answers = [] for _ in range(T): V, X = map(int, input().split()) ans = solve(V, X) answers.append(ans) for ans in answers: print(ans) if __name__ == '__main__': main()