#include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; void validate(int v, int x, vector a){ assert(a.size() == x); int p = x*v+1; vector tmp(x, 1); for(int i = 1; i <= x; i++){ // cout << i << ' '; for(int j = 0; j < x; j++) tmp[j] = (tmp[j]*a[j])%p; int sum = accumulate(tmp.begin(), tmp.end(), 0); // cout << i << ' ' << x << endl; // for(int s : tmp) cout << s << ' '; // cout << endl; // cout << sum%p << ' ' << p << endl; if(i == x) assert(sum%p == x); else assert(sum%p == 0); } } ll pow(ll a, ll n, ll MOD) { ll ans = 1; ll tmp = a; for (int i = 0; i <= 60; i++) { ll m = (ll)1 << i; if (m & n) { ans *= tmp; ans %= MOD; } tmp *= tmp; tmp %= MOD; } return ans; } void solve(){ int v, x; cin >> v >> x; int p = x*v+1; if(x == 1){ cout << 1 << endl; return; } int a = -1; for(int i = 2; i < p; i++){ bool ok = true; ll pw = pow(i, v, p); ll tmp = 1; for(int j = 1; j < x; j++){ tmp = (tmp*pw)%p; if(tmp == 1) ok = false; } if(ok){ a = i; break; } } assert(a != -1); vector ans; for(int i = 0; i < x; i++){ ans.push_back(pow(a, i*v, p)); } sort(ans.begin(), ans.end()); validate(v, x, ans); for(int x : ans) cout << x << ' '; cout << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int t; cin >> t; while(t--) solve(); }