#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++){ for(int j = 0; j < x; j++) tmp[j] = (tmp[j]*a[j])%p; int sum = accumulate(tmp.begin(), tmp.end(), 0); 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; int a = -1; for(int i = 2; i < p; i++){ if(pow(i, v, p) != 1){ a = i; break; } } 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(); }