#include"testlib.h"
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()

using namespace std;

const int T = 1e4;
const int MAX_N = 2e5;
const int MAX_Q = 2e5;

void slightly_shuffle(vector<int> &v) {
    int n = v.size();
    for (int t = 0; t < 5 * n; ++t) {
        int i = rnd.next(0, n - 1);
        int j = rnd.next(i - 5, i + 5);
        if (j < 0 || j >= n) continue;
        swap(v[i], v[j]);
    }
}

int32_t main(int argc, char *argv[]) {
    registerGen(argc, argv, 1);
    int a = opt<int>(1), b = opt<int>(2), mask = (5 * opt<int>(3) + 3) % 16;
    int n = a * b;
    int t = MAX_N / n;
    int q = MAX_Q / t;
    cout << t << '\n';
    for (int i = 0; i < t; ++i) {
        cout << n << ' ' << q << '\n';
        vector<vector<int>> blocks(b);
        for (int i = 0; i < n; ++i) blocks[i / a].push_back(i + 1);
        reverse(all(blocks));
        vector<int> res;
        for (auto &block : blocks) {
          if (mask & 1) slightly_shuffle(block);
          for (int x : block) res.push_back(x);
        }
        if (mask & 2) for (int &x : res) x = n + 1 - x;
        if (mask & 4) reverse(all(res));
        if (mask & 8) slightly_shuffle(res);
        for (int x : res) cout <<  x << " \n"[x == res.back()];
        for (int i = 0; i < q; ++i) {
            int l = rnd.next(1, n);
            int r = rnd.next(1, n);
            cout << min(l, r) << ' ' << max(l, r) << '\n';
        }
    }
}
