program generator;

{$APPTYPE CONSOLE}

uses
   SysUtils;

const MAXT = 1000;
      MAXV = 1000;
      MAXX = 1000000;

var i, tests, teq : integer;

procedure writeTest(t1, v1, t2, v2, X : integer);
begin
  tests := tests + 1;

  if (tests < 10) then 
    rewrite(output, '0' + InttoStr(tests))
  else
    rewrite(output, InttoStr(tests));

  writeln(t1, ' ', v1, ' ', t2, ' ', v2);
  writeln(X);

  close(output);
end;           

procedure genequalcars(X : integer);
var t, v : integer;
begin
  t := random(MAXT) + 1;
  v := random(MAXV) + 1;

  writeTest(t, v, t, v, X);
end;

function GCD(a, b : integer) : integer;
begin
  if (b = 0) then
    GCD := a
  else
    GCD := GCD(b, a mod b);
end;

procedure genaroundequal;
var t1, t2, v, X : integer;
begin
  v := random(MAXV) + 1;
  t1 := random(MAXT) + 1;
  t2 := random(MAXT) + 1;
  
  X := (v * t1 * t2) div GCD(t1, t2);
  
  if (X > MAXX) then
    exit;

  writeTest(t1, v, t2, v, X);
  teq := teq + 1;
end;

procedure genequal;
var t1, t2, v, X : integer;
begin
  v := random(MAXV) + 1;
  t1 := random(MAXT) + 1;
  t2 := random(MAXT) + 1;
  
  X := (v * t1 * t2) div GCD(t1, t2) + 1;
  
  if (X > MAXX) then
    exit;

  writeTest(t1, v, t2, v, X);
  teq := teq + 1;
end;

procedure genequalv(X : integer);
var t1, t2, v : integer;
begin
  v := random(MAXV) + 1;
  t1 := random(MAXT) + 1;
  t2 := random(MAXT) + 1;
  writeTest(t1, v, t2, v, X);
end;

procedure genequalT(X : integer);
var t, v1, v2 : integer;
begin
  v1 := random(MAXV) + 1;
  v2 := random(MAXV) + 1;
  t := random(MAXT) + 1;
  writeTest(t, v1, t, v2, X);
end;

procedure gen(MAX, MAXX : integer);
var t1, t2, v1, v2, X : integer;
begin
  t1 := random(MAX) + 1;
  t2 := random(MAX) + 1;
  v1 := random(MAX) + 1;
  v2 := random(MAX) + 1;
  X := MAXX;

  writeTest(t1, v1, t2, v2, X);
end;
         
begin
  RandSeed := 239;
  tests := 0;

  writeTest(1, 1, 2, 1, 4);
  writeTest(1, 1, 1, 1, 1);
  writeTest(1, 1, MAXT, 1, 1);
  writeTest(MAXT, 1, 1, 1, 1);
  writeTest(1, 1, MAXT, 1, 10);
  writeTest(MAXT, 1, 1, 1, 10);
  writeTest(1, MAXV, 1, 1, 1000);
  writeTest(MAXT, MAXV, 1, 1, 2000);
  writeTest(MAXT, 1, 1, 1, MAXX);

  for i := 1 to 2 do
    genequalcars(random(MAXX) + 1);
  genequalcars(MAXX);

  teq := 1;
  while (teq <= 2) do
    genequal;

  teq := 1;
  while (teq <= 2) do
    genaroundequal;

  for i := 1 to 2 do
    genequalv(random(MAXX) + 1);
  genequalv(MAXX);

  for i := 1 to 2 do
    genequalT(random(MAXX) + 1);
  genequalT(MAXX);

  for i := 1 to 4 do
    gen(100, 100);

  for i := 1 to 4 do
    gen(100, MAXX);

  for i := 1 to 4 do
    gen(MAXV, MAXX);

  writeTest(MAXT, MAXV, MAXT, random(MAXV) + 1, random(MAXX) + 1);
  writeTest(MAXT, MAXV, random(MAXT) + 1, MAXV, random(MAXX) + 1);
  writeTest(MAXT, MAXV, random(MAXT) + 1, random(MAXV) + 1, random(MAXX) + 1);
  writeTest(random(MAXT) + 1, MAXV, random(MAXT) + 1, MAXV, random(MAXX) + 1);
  writeTest(random(MAXT) + 1, MAXV, MAXT, random(MAXV) + 1, random(MAXX) + 1);
  writeTest(random(MAXT) + 1, MAXV, random(MAXT) + 1, random(MAXV) + 1, random(MAXX) + 1);
  writeTest(MAXT, random(MAXV) + 1, random(MAXT) + 1, MAXV, random(MAXX) + 1);
  writeTest(MAXT, random(MAXV) + 1, MAXT, random(MAXV) + 1, random(MAXX) + 1);
  writeTest(MAXT, random(MAXV) + 1, random(MAXT) + 1, random(MAXV) + 1, random(MAXX) + 1);
  writeTest(MAXT, MAXV, MAXT, MAXV, random(MAXX) + 1);
                                                      
  writeTest(MAXT, MAXV, MAXT, random(MAXV) + 1, MAXX);
  writeTest(MAXT, MAXV, random(MAXT) + 1, MAXV, MAXX);
  writeTest(MAXT, MAXV, random(MAXT) + 1, random(MAXV) + 1, MAXX);
  writeTest(random(MAXT) + 1, MAXV, random(MAXT) + 1, MAXV, MAXX);
  writeTest(random(MAXT) + 1, MAXV, MAXT, random(MAXV) + 1, MAXX);
  writeTest(random(MAXT) + 1, MAXV, random(MAXT) + 1, random(MAXV) + 1, MAXX);
  writeTest(MAXT, random(MAXV) + 1, random(MAXT) + 1, MAXV, MAXX);
  writeTest(MAXT, random(MAXV) + 1, MAXT, random(MAXV) + 1, MAXX);
  writeTest(MAXT, random(MAXV) + 1, random(MAXT) + 1, random(MAXV) + 1, MAXX);
  writeTest(MAXT, MAXV, MAXT, MAXV, MAXX);
end.