#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define reps(x, s) for(llint (x) = 0; (x) < (llint)(s).size(); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define ceildiv(x, y) (((x)+(y)-1) / (y)) #define all(x) (x).begin(),(x).end() #define outl(x) cout << x << endl #define SP << " " << #define inf 1e18 //#define mod 1000000007 using namespace std; typedef long long llint; typedef long long ll; typedef pair P; bool exceed(ll x, ll y, ll m){return x >= m / y + 1;} ll T; ll v, x; vector vec[100005]; llint modpow(llint a, llint n, ll mod) { if(n == 0) return 1; if(n % 2){ return ((a%mod) * (modpow(a, n-1, mod)%mod)) % mod; } else{ return modpow((a*a)%mod, n/2, mod) % mod; } } int main(void) { ios::sync_with_stdio(0); cin.tie(0); rep(i, 1, 100000){ for(int j = 2*i; j < 100005; j+=i) vec[j].push_back(i); } cin >> T; while(T--){ cin >> v >> x; ll p = v*x+1; if(p == 2){ cout << 1 << endl; continue; } ll a; rep(i, 2, p-1){ bool flag = true; for(auto e : vec[p-1]){ if(modpow(i, e, p) == 1){ flag = false; break; } } if(flag){ a = i; break; } } a = modpow(a, v, p); vector ans; rep(i, 1, x) ans.push_back(modpow(a, i, p)); sort(all(ans)); for(auto x : ans) cout << x << " "; cout << endl; } return 0; }