#include #include #include #include using namespace std; long long modexp(int x, long long e, int m) { long long ans = 1, p = x % m; while (e > 0) { if (e % 2 != 0) ans = (ans * p) % m; p = (p * p) % m; e >>= 1; } return ans; } void check(int v, int x, vector& ans) { const int p = v * x + 1; for (int i = 1; i < x; i++) { long long sum = 0; for (int a : ans) sum += modexp(a, i, p); cerr << i << ' ' << sum << endl; assert(sum % p == 0); } long long sum = 0; for (int a : ans) sum += modexp(a, x, p); assert(sum % p == x); } int main() { int t; cin >> t; while (t--) { int x, v; cin >> v >> x; const int p = x * v + 1; if (x == 1) { cout << "1\n"; continue; } vector ds; int y = x * v; for (int i = 2; i * i <= y; i++) { if (y % i == 0) { ds.push_back(i); while (y % i == 0) y /= i; } } if (y > 1) ds.push_back(y); for (int g = 2; ; g++) { bool ok = true; for (int d : ds) { if (modexp(g, x * v / d, p) == 1) { ok = false; break; } } if (ok) { vector ans; long long b = modexp(g, v, p), p = 1; for (int i = 0; i < x; i++) { ans.push_back(p); p = p * b % (x * v + 1); } sort(ans.begin(), ans.end()); for (int i = 0; i < x; i++) { cout << (i == 0 ? "" : " ") << ans[i]; } cout << endl; // check(v, x, ans); break; } } } }