#include "testlib.h"
#include <cassert>

using namespace std;

#define MAXT 1000
#define MAXN 5000

char buf[256];
vector <string> out;

int main(int argc, char *argv[]) {
  registerGen (argc, argv, 1);
  assert(argc == 5 || argc == 6);
  int mn = atoi(argv[2]);
  int ma = atoi(argv[3]);
  int mb = atoi(argv[4]);
  int nsum = 0, tsum = 0;
  while (1) {
    int n, a, b;
    do {
      n = argc == 6 ? mn : rnd.next(1, mn);
      a = argc == 6 ? ma : rnd.next(1, ma);
      b = argc == 6 ? mb : rnd.next(1, mb);
    } while (n > (long long)a * b);
    nsum += n;
    tsum++;
    if (tsum > MAXT || nsum > MAXN) break;
    set <pair <int, int>> S;
    snprintf(buf, 255, "%d %d %d", n, a, b);
    out.push_back(buf);
    for (int i = 0; i < n; i++) {
      int ca, cb;
      do {
        ca = rnd.next(1, a);
        cb = rnd.next(1, b);
      } while (S.find(make_pair(ca, cb)) != S.end());
      S.insert(make_pair(ca, cb));
      snprintf(buf, 255, "%d %d", ca, cb);
      out.push_back(buf);
    }
  }
  printf("%d\n", tsum - 1);
  for (int i = 0; i < (int)out.size(); i++) puts(out[i].c_str());
}
