#ifdef DEBUG
#  define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include "testlib.h"
#define ff first
#define ss second
#define szof(x) ((int)x.size())
#ifndef LOCAL
#  define cerr __get_ce
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;

class dsu {
 public:
  vector<int> p;
  int n;

  dsu(int _n) : n(_n) {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }

  inline int get(int x) {
    return (x == p[x] ? x : (p[x] = get(p[x])));
  }

  inline bool unite(int x, int y) {
    x = get(x);
    y = get(y);
    if (x != y) {
      p[x] = y;
      return true;
    }
    return false;
  }
};

int main(int argc, char* argv[]) {
  registerGen(argc, argv, 1);

  int t = opt<int>("t");
  int minn = opt<int>("minn");
  int maxn = opt<int>("maxn");
  int minm = opt<int>("minm");
  int maxm = opt<int>("maxm");

  int ratio = (maxm + maxn - 1) / maxn;

  auto ns = rnd.partition(t, maxn, minn);
  int sum_m = 0;
  
  cout << t << '\n';
  for (int q = 0; q < t; q++) {
    int n = ns[q];
    int limit = minm + ((maxm - sum_m) - minm * (t - q));
    limit = min(limit, ratio * n);
    if (n < 10000) {
      limit = min(limit, n * (n - 1));
    }
    assert(minm <= limit);
    int m = rnd.next(minm, limit);
    sum_m += m;
    cout << n << " " << m << '\n';
    set<pair<int, int>> s;
    while (m--) {
      int u, v;
      do {
        u = rnd.next(1, n);
        v = rnd.next(1, n);
      } while (u == v || s.find(make_pair(u, v)) != s.end());
      s.emplace(u, v);
      cout << u << " " << v << '\n';
    }
  }

  return 0;
}