#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>

#include "random.h"

using namespace std;

const int maxN = 100000;

int n, k, x[maxN], y[maxN], l[maxN], r[maxN];

int main( int argc, char *argv[] ) {
  assert(argc == 5);
  n = atoi(argv[1]);
  k = atoi(argv[2]);
  int m = atoi(argv[3]);
  initrand(atoi(argv[4]));
  for (int i = 0; i < n; ++i) {
    x[i] = R(1, m);
    y[i] = R(1, m);
  }
  for (int i = 0; i < k; ++i) {
    do {
      l[i] = R(0, n - 1);
      r[i] = R(0, n - 1);
    } while (l[i] == r[i]);
    if (l[i] > r[i]) {
      swap(l[i], r[i]);
    }
  }
  printf("%d\n", n);
  for (int i = 0; i < n; ++i) {
    printf("%d %d\n", x[i], y[i]);
  }
  printf("%d\n", n);
  for (int i = 0; i < n; ++i) {
    printf("%d %d\n", l[i] + 1, r[i] + 1);
  }
  fprintf(stderr, "Случайный тест со случайными запросами, n=%d, k=%d\n", n, k);

  return 0;
}
