#define _USE_MATH_DEFINES #include using namespace std; using ll = long long; using ull = unsigned long long; using pil = pair; using pli = pair; using pii = pair; using vi = vector; using vvi = vector; using vvvi = vector; using pll = pair; using vl = vector; using vvl = vector; using vvvl = vector; using pbb = pair; using vb = vector; using vvb = vector; using vvvb = vector; using pcc = pair; using vc = vector; using vvc = vector; using vvvc = vector; using pss = pair; using vs = vector; using vvs = vector; using vvvs = vector; using pdd = pair; using vd = vector; using vvd = vector; using vvvd = vector; template using pq = priority_queue>; template using pql = priority_queue, greater>; #define rep0(times) for(int counter = 0; counter < (int)(times); ++counter) #define rep(counter, goal) for (int counter = 0; counter < (int)(goal); ++counter) #define rep2(counter, start, goal) for (int counter = (int)(start); counter < (int)(goal); ++counter) #define rep3(counter, start, goal) for (int counter = (int)(start); counter > (int)(goal); --counter) #define all(container) begin(container), end(container) template bool chmax(T &x, const T &y) { if (x < y) { x = y; return true; } return false; } template bool chmin(T &x, const T &y) { if (x > y) { x = y; return true; } return false; } void Yn(bool flag) { cout << (flag ? "Yes" : "No") << "\n"; } void yn(bool flag) { cout << (flag ? "yes" : "no") << "\n"; } void YN(bool flag) { cout << (flag ? "YES" : "NO") << "\n"; } void set_prec(const int &digits) { cout << fixed << setprecision(digits); cerr << fixed << setprecision(digits); } template T INF() { return numeric_limits::max(); } #include using namespace atcoder; // using mint = atcoder::modint1000000007; // using mint = atcoder::modint998244353; using mint = atcoder::modint; using pmm = pair; using vm = vector; using vvm = vector; using vvvm = vector; void pr(const mint &obj) { cerr << obj.val(); } template void pr(const T &obj) { cerr << obj; } template void pr(const T &first, const Ts &...rest) { pr(first); pr(", "); pr(rest...); } template void pr(const pair &pair) { pr("("); pr(pair.first); pr(", "); pr(pair.second); pr(")"); } template void pr(const vector &vec) { pr("{"); for (T obj : vec) { pr(obj); pr(", "); } pr("}"); } template void pr(const vector> &vv) { pr("\n"); rep(index, vv.size()) { pr("["); pr(index); pr("]: "); pr(vv[index]); pr("\n"); } } template void pr(const set &vec) { pr("{"); for (T obj : vec) { pr(obj); pr(", "); } pr("}"); } template void pr(const map &map) { pr("{"); for (pair pair : map) { pr("("); pr(pair.first); pr(": "); pr(pair.second); pr("), "); } pr("}"); } #define db(obj) cerr << #obj << ": "; pr(obj); cerr << " " #define dl(obj) db(obj); cerr << "\n" #define dm(...) cerr << "(" << #__VA_ARGS__ << "): ("; pr(__VA_ARGS__); cerr << ") " #define dml(...) dm(__VA_ARGS__); cerr << "\n" const ll MOD = 1000000007; // const ll MOD = 998244353; // mod p = xv+1 で 位数 x の元 a を見つければよい // a, a^2, a^3,... a^(x-1), a^x(=1) をソートしたものが所望の数列となる void solve() { int v, x; cin >> v >> x; int p = v * x + 1; // dl(p); // * mint::set_mod(p); rep2(i, 1, p) { vb r(p, true); r[0] = false; int cur = i; for (; cur < p; ++cur) { if (!r[cur]) continue; set w; w.insert(1); mint a(cur); // dl(cur); for (; a != 1; a *= cur) { w.insert(a.val()); r[a.val()] = false; } // dl(r); dl(w); dl(w.size()); if (w.size() == x) { for (int wi : w) { cout << wi << " "; } cout << endl; return; } else if (w.size() > x) { int t = w.size() / x; mint a = mint(cur).pow(t); vi u; mint b(1); u.push_back(b.val()); rep0(x - 1) { b *= a; u.push_back(b.val()); } sort(all(u)); for (int ui : u) { cout << ui << " "; } cout << endl; return; } } } } int main() { int T; cin >> T; rep0(T) solve(); }