//#define _GLIBCXX_DEBUG #include using namespace std; #define rep(i, n) for(int i=0; i; using vs = vector; using vi = vector; using vvi = vector; template using PQ = priority_queue; template using PQG = priority_queue, greater>; const int INF = 0xccccccc; const ll LINF = 0xcccccccccccccccLL; template inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template istream &operator>>(istream &is, pair &p) { return is >> p.first >> p.second;} template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ' ' << p.second;} constexpr int64_t safe_mod(int64_t x, int64_t m) { x %= m; if(x < 0) x += m; return x; } constexpr pair inv_gcd(int64_t a, int64_t b) { a = safe_mod(a, b); if(a == 0) return {b, 0}; int64_t s = b, t = a; int64_t m0 = 0, m1 = 1; while(t) { int64_t u = s/t; s -= t*u; m0 -= m1*u; int64_t tmp = s; s = t; t = tmp; tmp = m0; m0 = m1; m1 = tmp; } if(m0 < 0) m0 += b/s; return {s, m0}; } // 最初に d_mint::set_mod(m) を行う struct d_mint { struct barrett { unsigned int _m; uint64_t im; barrett(unsigned int m):_m(m), im(uint64_t(-1)/m + 1) {} unsigned int umod() const {return _m;} unsigned int mul(unsigned int a, unsigned int b) const { uint64_t z = a; z *= b; uint64_t x = uint64_t(((unsigned __int128)(z)*im) >> 64); unsigned int v = (unsigned int)(z-x*_m); if(_m <= v) v += _m; return v; } }; unsigned int x; static barrett bt; static unsigned int umod() {return bt.umod();} static int mod() {return int(bt.umod());} static void set_mod(int m) { assert(1 <= m); bt = barrett(m); } static d_mint raw(int v) { d_mint z; z.x = v; return z; } d_mint() : x(0) {} template d_mint(T v) { int64_t z = int64_t(v % int64_t(mod())); if(z < 0) z += mod(); x = (unsigned int)(z); } d_mint& operator++() { x++; if(x == umod()) x = 0; return *this; } d_mint& operator--() { if(x == 0) x = umod(); x--; return *this; } d_mint operator++(int) { d_mint result = *this; ++*this; return result; } d_mint operator--(int) { d_mint result = *this; --*this; return result; } d_mint& operator+=(const d_mint &rhs) { x += rhs.x; if(x >= umod()) x -= umod(); return *this; } d_mint& operator-=(const d_mint &rhs) { x += mod() - rhs.x; if(x >= umod()) x -= umod(); return *this; } d_mint& operator*=(const d_mint &rhs) { x = bt.mul(x, rhs.x); return *this; } d_mint& operator/=(const d_mint& rhs) { return *this = *this * rhs.inv(); } d_mint operator+() const {return *this;} d_mint operator-() const {return d_mint() - *this;} d_mint pow(int64_t n) const { assert(0 <= n); d_mint z = *this, r = 1; while(n) { if(n&1) r *= z; z *= z; n >>= 1; } return r; } d_mint inv() const { auto eg = inv_gcd(x, mod()); assert(eg.first == 1); return eg.second; } friend d_mint operator+(const d_mint &lhs, const d_mint &rhs) { return d_mint(lhs) += rhs; } friend d_mint operator-(const d_mint &lhs, const d_mint &rhs) { return d_mint(lhs) -= rhs; } friend d_mint operator*(const d_mint &lhs, const d_mint &rhs) { return d_mint(lhs) *= rhs; } friend d_mint operator/(const d_mint &lhs, const d_mint &rhs) { return d_mint(lhs) /= rhs; } friend bool operator==(const d_mint &lhs, const d_mint &rhs) { return lhs.x == rhs.x; } friend bool operator!=(const d_mint &lhs, const d_mint &rhs) { return lhs.x != rhs.x; } friend istream &operator>>(istream &is, d_mint &x) {return is >> x.x;} friend ostream &operator<<(ostream &os, const d_mint &x) {return os << x.x;} }; d_mint::barrett d_mint::bt = 998244353; constexpr int64_t pow_mod_constexpr(int64_t x, int64_t n, int m) { if(m == 1) return 0; unsigned int _m = (unsigned int)(m); uint64_t r = 1; uint64_t y = safe_mod(x, m); while(n) { if(n&1) r = (r*y)%_m; y = (y*y)%_m; n >>= 1; } return r; } constexpr int primitive_root_constexpr(int m) { if(m == 2) return 1; if(m == 167772161) return 3; if(m == 469762049) return 3; if(m == 754974721) return 11; if(m == 998244353) return 3; int divs[20] = {}; divs[0] = 2; int cnt = 1; int x = (m-1)>>1; while(~x&1) x >>= 1; for(int i = 3; (int64_t)(i)*i <= x; i += 2) { if(x%i == 0) { divs[cnt++] = i; while(x%i == 0) x /= i; } } if(x > 1) divs[cnt++] = x; for(int g = 2;; g++) { bool ok = true; for(int i = 0; i < cnt; i++) { if(pow_mod_constexpr(g, (m-1)/divs[i], m) == 1) { ok = false; break; } } if(ok) return g; } } //head int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while(t--) { int v, x; cin >> v >> x; int mod = v*x+1; d_mint::set_mod(mod); d_mint g = primitive_root_constexpr(mod); g = g.pow(v); d_mint now(1); vi ans(x); rep(i, x) { now *= g; ans[i] = now.x; } sort(all(ans)); rep(i, x) cout << ans[i] << (i == x-1?'\n':' '); } }