#include "dango3.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
namespace {
int variable_example = 1;
int n, m;
} // namespace
// excluding exc, find first pos in [l, r] which returns 1
int func(int l, int r, vector<int> exc = {}, vector<int> inc = {}) {
int lo = l - 1;
int hi = r + 1;
if (l == r) return l;
while (hi > lo + 1) {
int mid = (lo + hi) / 2;
vector<int> in(n*m); for (int i = l; i <= mid; i++) in[i] = 1;
for (auto &x : exc) in[x] = 0;
for (auto &x : inc) in[x] = 1;
vector<int> qry; for (int i = 0; i < n*m; i++) if (in[i]) qry.push_back(i + 1);
int q = Query(qry);
if (q > 0) hi = mid;
else lo = mid;
}
return hi;
}
void Solve(int N, int M) {
n = N; m = M;
vector<vector<int>> block(N);
int rp = n * m - 1; vector<int> inctmp;
for (int i = 0; i < N; i++) {
int f = func(0, rp, {}, inctmp);
block[i].push_back(f);
inctmp.push_back(f);
rp = f - 1;
// cout << f+1 << " is a start\n";
}
for (int i = 0; i < N; i++) {
// cout << "#" << i+1 << '\n';
for (int j = 1; j < M; j++) {
// disinclude everything in this
vector<int> dis; for (auto &x : block[i]) dis.push_back(x);
vector<int> inc; for (int other = 0; other < N; other++) {
if (other == i) continue;
inc.push_back(block[other][0]);
}
int nxt = func(0, n*m - 1, dis, inc);
block[i].push_back(nxt);
// cout << nxt << " is found\n";
}
}
// for (int i = 0; i < N; i++) {
// for (auto &x : block[i]) cout << x+1 << " ";
// cout << '\n';
// }
for (int i = 0; i < M; i++) {
vector<int> cur; for (int j = 0; j < N; j++) cur.push_back(block[j][i]+1);
Answer(cur);
}
}