import java.io.*;
import java.util.*;

public class Tests {
  static int nTests = 0;
  static final File root = new File("../tests");

  static void write(String... testText) {
    try (PrintWriter out = new PrintWriter(String.format("%s/%02d", root.getAbsolutePath(), ++nTests))) {
      System.out.println("Writing test " + nTests);
      for (String s : testText) {
        out.print(s + "\r\n");
//        out.println(s);
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  static void write(TestInfo test) {
    write(test.toText());
  }

  static final Random random = new Random(3204723570832407424L);

  private static void writeRandom(int n, int l, int r, int maxA, DifferenceGenerator generator) {
    TestInfo test = new TestInfo(n, l, r);
    for (int i = 0; i < n; ++i) {
      int diff = generator.nextDiff();
      int a, b;
      if (diff >= 0) {
        b = random.nextInt(maxA - diff) + 1;
        a = b + diff;
      } else {
        a = random.nextInt(maxA + diff) + 1;
        b = a - diff;
      }
      test.addCity(a, b);
    }
    write(test);
  }

  private static void writeRandom(int n, int l, int r, int maxA) {
    writeRandom(n, l, r, maxA, new UniformDifferenceGenerator(-maxA + 1, maxA - 1));
  }

  private static abstract class DifferenceGenerator {
    public abstract int nextDiff();
  }

  private static final class PeriodicDifferenceGenerator extends DifferenceGenerator {
    public PeriodicDifferenceGenerator(int[] period) {
      this.period = period;
      this.index = 0;
    }

    @Override
    public int nextDiff() {
      int res = period[index];
      index++;
      if (index == period.length) {
        index = 0;
      }
      return res;
    }

    private final int[] period;
    private int index;
  }

  private static final class UniformDifferenceGenerator extends DifferenceGenerator {
    public UniformDifferenceGenerator(int minD, int maxD) {
      this.minD = minD;
      this.maxD = maxD;
    }

    @Override
    public int nextDiff() {
      return random.nextInt(maxD - minD + 1) + minD;
    }

    private final int minD;
    private final int maxD;
  }

  private static final class ComplexDifferenceGenerator extends DifferenceGenerator {
    public ComplexDifferenceGenerator(DifferenceGenerator first, DifferenceGenerator second, double p) {
      this.first = first;
      this.second = second;
      this.p = p;
    }

    @Override
    public int nextDiff() {
      if (random.nextDouble() <= p) {
        return first.nextDiff();
      } else {
        return second.nextDiff();
      }
    }

    private final DifferenceGenerator first;
    private final DifferenceGenerator second;
    private final double p;
  }

  private static final class TestInfo {
    private final int n, l, r;
    private final ArrayList<Integer> A;
    private final ArrayList<Integer> B;

    public TestInfo(int n, int l, int r) {
      this.n = n;
      this.l = l;
      this.r = r;
      A = new ArrayList<Integer>(n);
      B = new ArrayList<Integer>(n);
    }

    public void addCity(int a, int b) {
      A.add(a);
      B.add(b);
    }

    public String[] toText() {
      assert this.n == A.size();
      assert this.n == B.size();
      ArrayList<String> s = new ArrayList<String>();
      s.add(String.format("%d %d %d", n, l, r));
      for (int i = 0; i < n; ++i) {
        s.add(String.format("%d %d", A.get(i), B.get(i)));
      }
      return s.toArray(new String[s.size()]);
    }
  }

  private static void writeSamples() {
    write("5 1 2", "7 5", "10 1", "2 3", "2 6", "4 3");
  }

  public static void main(String[] args) {
    root.mkdir();        
    writeSamples();

    write("4 1 2", "1 10", "1 10", "1 10", "1 10");
    write("4 1 4", "11 1", "1 10", "1 10", "11 1");
    write("5 1 3", "9 3", "2 7", "8 9", "9 1", "5 1");
    write("7 1 3", "1 10", "1 10", "1 10", "4 4", "10 1", "1 2", "1 2");
    write("7 1 3", "10 1", "1 2", "1 2", "4 4", "1 10", "1 10", "1 10");
    write("10 1 2", "3 6", "4 1", "1 5", "4 1", "2 9", "3 5", "2 2", "5 6", "9 1", "3 1");
    write("10 1 2", "4 4", "10 1", "4 9", "5 4", "2 2", "7 8", "7 9", "1 3", "8 7", "1 5");
    write("1 1 1", "10000 1");
    write("1 1 1", "1 10000");
    write("1 1 1", "10000 10000");
    writeRandom(100000, 1, 100, 10000, new ComplexDifferenceGenerator(new UniformDifferenceGenerator(9000, 9999), new UniformDifferenceGenerator(-100, 0), 0.01));
    writeRandom(100000, 1, 100000, 10000, new ComplexDifferenceGenerator(new UniformDifferenceGenerator(9000, 9999), new UniformDifferenceGenerator(-100, 0), 0.01));
    writeRandom(100000, 30000, 80000, 10000, new ComplexDifferenceGenerator(new UniformDifferenceGenerator(9000, 9999), new UniformDifferenceGenerator(-100, 0), 0.01));
    writeRandom(100000, 100, 10000, 10000, new ComplexDifferenceGenerator(new UniformDifferenceGenerator(9000, 9999), new UniformDifferenceGenerator(-100, 0), 0.9));
    writeRandom(100000, 100, 10000, 10000, new ComplexDifferenceGenerator(new UniformDifferenceGenerator(9000, 9999), new UniformDifferenceGenerator(-100, 0), 0.9));
    writeRandom(100000, 1, 100, 10000, new ComplexDifferenceGenerator(new UniformDifferenceGenerator(9000, 9999), new UniformDifferenceGenerator(-100, 0), 0.9));
    writeRandom(100000, 1, 100000, 10000, new UniformDifferenceGenerator(-9999, 0));
    writeRandom(100000, 1, 48723, 10000, new UniformDifferenceGenerator(-9999, 0));
    writeRandom(100000, 20000, 68723, 10000, new UniformDifferenceGenerator(-9999, 0));
    writeRandom(100000, 1, 50001, 10000, new UniformDifferenceGenerator(-9999, 0));
    writeRandom(100000, 1, 50000, 10000, new UniformDifferenceGenerator(0, 0));
    writeRandom(100000, 1, 50000, 10000, new PeriodicDifferenceGenerator(new int[]{8888,-8888}));
    writeRandom(100000, 1, 10000, 10000, new PeriodicDifferenceGenerator(new int[]{8888,-8888}));
    writeRandom(100000, 1, 50000, 10000, new PeriodicDifferenceGenerator(new int[]{2,-1,-1}));
    writeRandom(100000, 5000, 80000, 10000, new PeriodicDifferenceGenerator(new int[]{2,-1,-1}));
    writeRandom(100000, 1, 50000, 10000, new PeriodicDifferenceGenerator(new int[]{1,-2,1}));
    writeRandom(100000, 1, 30000, 10000, new PeriodicDifferenceGenerator(new int[]{1,-2,1}));
    writeRandom(100000, 1, 50000, 10000, new PeriodicDifferenceGenerator(new int[]{2, -1, -2, 1, -10}));
    writeRandom(100000, 10, 50000, 10000, new PeriodicDifferenceGenerator(new int[]{2, -1, -2, 1, -10}));
    writeRandom(100000, 1, 11111, 10000, new UniformDifferenceGenerator(-9999, 0));
    writeRandom(100000, 1, 11111, 10000, new UniformDifferenceGenerator(1, 9999));
    writeRandom(100000, 1, 100000, 10000, new UniformDifferenceGenerator(1, 9999));
    writeRandom(100000, 1, 100, 10);
    writeRandom(100000, 1000, 2000, 100);
    writeRandom(89999, 40000, 50000, 100);
    writeRandom(100000, 1, 100, 10000);
    writeRandom(100000, 1, 1000, 10000);
    writeRandom(99999, 49999, 50000, 10000);
    writeRandom(100000, 100000, 100000, 10000);
    writeRandom(100000, 1, 100000, 10000);
    writeRandom(100000, 50001, 100000, 10000);
    writeRandom(100000, 1, 50000, 10000);
  }
}
