#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef int64_t ll; typedef std::pair Pii; typedef std::pair Pll; typedef std::pair Pdd; #define rip(_i, _n, _s) for (int _i = (_s); _i < (int)(_n); _i++) #define all(_l) _l.begin(), _l.end() #define rall(_l) _l.rbegin(), _l.rend() #define MM << " " << template using MaxHeap = std::priority_queue<_T>; template using MinHeap = std::priority_queue<_T, std::vector<_T>, std::greater<_T>>; template inline bool chmax(_T &_l, const _T _b) { if (_l < _b) { _l = _b; return true; } return false; } template inline bool chmin(_T &_l, const _T _b) { if (_l > _b) { _l = _b; return true; } return false; } // # ifdef LOCAL_DEBUG template void vdeb(const std::vector<_T> &bb) { for (unsigned int i = 0;i < bb.size();i++) { if (i == bb.size() - 1) std::cout << bb[i]; else std::cout << bb[i] << ' '; } std::cout << '\n'; } template void vdeb(const std::vector> &bb) { for (unsigned int i = 0;i < bb.size();i++) { std::cout << i << ' '; vdeb(bb[i]); } std::cout << '\n'; } // # endif using namespace std; long long modpow(long long _n, long long _k, long long _p) { long long _ret = 1, _now = _n; while(_k) { if(_k&1) _ret = _ret * _now % _p; _now = _now * _now % _p; _k >>= 1; } return _ret; } void solve() { int v, x; cin >> v >> x; int p = v*x + 1, an = 1; rip(i,p,1) { int now = 1; bool flg = true; rip(j,x-1,0) { now = now*i%p; if(now%p == 1) { flg = false; break; } } if(flg) { now = i*now%p; if(now == 1) { an = i; break; } } } vector ans(x); ans[0] = 1; rip(i,x,1) ans[i] = ans[i-1]*an%p; sort(all(ans)); vdeb(ans); } int main() { int t; cin >> t; rip(i,t,0) solve(); }