#include #include #include using namespace std; typedef long long ll; ll modpow(ll x, ll n, ll m){ ll res = 1, r = x; while(n){ if(n & 1) res = res * r % m; r = r * r % m; n >>= 1; } return res; } std::vector enum_prime(int n){ // containing n std::vector res; if (n <= 1) return res; std::vector p(n + 1); fill(p.begin() + 2, p.end(), true); for(int i = 2; i <= n; i++){ if(p[i]){ res.push_back(i); for(int j = i * 2; j <= n; j += i) p[j] = false; } } return res; } int main() { int t; cin >> t; vector prime = enum_prime(1002); while(t--){ ll v, x; cin >> v >> x; ll m = v * x + 1; vector w; ll l = m - 1; for(int p : prime){ if(l % p == 0) w.push_back(p); } ll r; for(r = 2; r < m; r++){ bool f = true; for(int p : w){ if(modpow(r, (m - 1) / p, m) == 1){ f = false; break; } } if(f) break; } r = modpow(r, v, m); ll a[102]; a[0] = 1; for(int i = 1; i <= x; i++) a[i] = a[i - 1] * r % m; for(int c = 1; c <= x; c++){ ll s = 0; for(int i = 1; i <= x; i++) s = (s + modpow(a[i], c, m)) % m; } sort(a + 1, a + x + 1); for(int i = 1; i <= x; i++) cout << a[i] << " "; cout << endl; } }