#ifdef LOCAL #include "debug.h" #else #include #define debug(x...) #endif #define int ll //#pragma GCC optimize("Ofast") using namespace std; typedef long long ll; typedef long double ld; typedef pair pii; #define sz(x) int((x).size()) #ifdef ONLINE_JUDGE mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #else mt19937 rng(1000 - 7); #endif const int N = 3e3 + 10; const int M = 1e3 + 10; const int MOD = 998244353; //const int MOD = 1e9 + 7; const ld eps = 1e-6; const pii dir[] = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } }; signed main() { #ifdef LOCAL //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif cout << fixed << setprecision(9); //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n; cin >> n; int a[n + 1][n + 1]; for (int i = 0; i < n; i++) { a[0][i] = i; } for (int i = 1; i < n; i++) { a[i][n - 1] = a[i - 1][n - 1] + 1; } for (int d = 1; d < n + n - 1; d++) { for (int i = 1, j = d - 1; j >= 0; i++, j--) { if (j + 1 < n) a[i][j] = a[i - 1][j + 1] + 1; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << (1LL << a[i][j]) << " "; } cout << "\n"; } int up[n][n]; up[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i + j == 0) { continue; } if (j) { up[i][j] = up[i][j - 1] + (1LL << a[i][j]); } else { up[i][j] = up[i - 1][j] + (1LL << a[i][j]); } } } debug(up[n - 1][n - 1]); int q; cin >> q; while (q--) { int x; cin >> x; int i = n - 1, j = n - 1; vector ans; ans.push_back({ n - 1, n - 1 }); while (!(i == 0 && j == 0)) { x -= (1LL << a[i][j]); if (i == 0) { ans.push_back({ i, j - 1 }); j--; } else if (j == 0) { ans.push_back({ i - 1, j }); i--; } else { if (x > up[i - 1][j]) { ans.push_back({ i, j - 1 }); j--; } else { ans.push_back({ i - 1, j }); i--; } } } reverse(ans.begin(), ans.end()); for (auto [x, y] : ans) { cout << x + 1 << " " << y + 1 << "\n"; } } return 0; }