using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); static int[] LList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => int.Parse(ReadLine())).ToArray(); public static void Main() { Solve(); } static void Solve() { var r = new Random(); var t = NN; var ans = new int[t][]; for (var u = 0; u < t; ++u) { var c = NList; var (v, x) = (c[0], c[1]); ans[u] = Math(r, v, x); } WriteLine(string.Join("\n", ans.Select(ai => string.Join(" ", ai)))); } static int[] Math(Random r, int v, int x) { if (x == 1) return new int[] { 1 }; if (v == 1) { var _ans = new int[x]; for (var i = 0; i < x; ++i) _ans[i] = i + 1; return _ans; } var p = PDiv(v); foreach (var kv in PDiv(x)) if (!p.ContainsKey(kv.Key)) p[kv.Key] = kv.Value; var b = 0; while (true) { b = r.Next(v * x) + 1; var flg = true; foreach (var kv in p) { if (Exp(b, v * x / kv.Key, v * x + 1) == 1) { flg = false; break; } } if (flg) break; } var ans = new int[x]; for (var i = 0; i < x; ++i) { ans[i] = (int)Exp(b, i * v, v * x + 1); } Array.Sort(ans); return ans; } static Dictionary PDiv(long n) { var dic = new Dictionary(); var tmp = n; while (tmp % 2 == 0) { tmp /= 2; if (dic.ContainsKey(2)) ++dic[2]; else dic.Add(2, 1); } for (var p = 3L; p * p <= n; p += 2) { while (tmp % p == 0) { tmp /= p; if (dic.ContainsKey(p)) ++dic[p]; else dic.Add(p, 1); } if (tmp == 1) break; } if (tmp > 1) dic.Add(tmp, 1); return dic; } static long Exp(long n, long p, int mod) { long _n = n % mod; var _p = p; var result = 1L; if ((_p & 1) == 1) result *= _n; while (_p > 0) { _n = _n * _n % mod; _p >>= 1; if ((_p & 1) == 1) result = result * _n % mod; } return result; } static bool IsPrime(int n) { if (n == 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; int i = 3; while (i * i <= n) { if (n % i == 0) return false; i = i + 2; } return true; } }