{
TASK: SKYLE
LANG: PASCAL
}
program skyle;

  const PRF = 'SKYLE.DAT';
        RZF = 'SKYLE.REZ';
        MAX_N = 50;
  type taskas = record
                  x, y: integer;
                end;
       virsunes = array [1..MAX_N] of taskas;

  var M1, M2, N: integer;
      v: virsunes;

  procedure rasti_stac (var vk, ad: taskas);
    var i: integer;
  begin
    vk.x := v[1].x; vk.y := v[1].y;
    ad.x := v[1].x; ad.y := v[1].y;
    for i := 2 to N do
      begin
        if vk.x > v[i].x then vk.x := v[i].x;
        if vk.y < v[i].y then vk.y := v[i].y;
        if ad.x < v[i].x then ad.x := v[i].x;
        if ad.y > v[i].y then ad.y := v[i].y;
      end;
  end; { rasti_staè }

  procedure dengti (vk, ad: taskas; var galima: boolean; var kiek: integer;
                    var vk1, vk2, ad1, ad2: taskas);
    var var1, var2, var3, var4, var5, var6: boolean;
  begin
    var1 := (vk.x + M1 >= ad.x) and (ad.y + M2 >= vk.y); { 1 nepasuktas }
    var2 := (vk.x + M2 >= ad.x) and (ad.y + M1 >= vk.y); { 1 pasuktas }
    var3 := (vk.x + 2*M1 >= ad.x) and (ad.y + M2 >= vk.y); { 00 nepasukti }
    var4 := (vk.x + 2*M2 >= ad.x) and (ad.y + M1 >= vk.y); { 00 pasukti }
    var5 := (vk.x + M1 >= ad.x) and (ad.y + 2*M2 >= vk.y); { = nepasuktas }
    var6 := (vk.x + M2 >= ad.x) and (ad.y + 2*M1 >= vk.y); { = pasuktas }
    galima := var1 or var2 or var3 or var4 or var5 or var6;
    if not galima then exit; { iðeinama ið procedûros }
    { randamas pirmasis taðkas }
    vk1 := vk;
    if var1
        then begin ad1.x := vk1.x + M1; ad1.y := vk1.y - M2; end
    else if var2
        then begin ad1.x := vk1.x + M2; ad1.y := vk1.y - M1; end;

        { randamas kiekis }
    if var1 or var2
       then kiek := 1
       else kiek := 2;
    if kiek = 1 then exit;
    { jei reikia 2-ju staèiakampiø  }
    if var1 or var3 or var5
        then begin ad1.x := vk1.x + M1; ad1.y := vk1.y - M2; end
        else begin ad1.x := vk1.x + M2; ad1.y := vk1.y - M1; end;

    vk2 := vk1; ad2 := ad1;
    if var3 then
       begin vk2.x := vk1.x + M1; ad2.x := ad1.x + M1; end
    else if var4 then
       begin vk2.x := vk1.x + M2; ad2.x := ad1.x + M2 end
    else if var5 then
       begin ad2.y := ad1.y - M2; vk2.y := vk1.y - M2; end
    else   { var6 }
        begin ad2.y := ad1.y - M1; vk2.y := vk1.y - M1; end;
  end; { dengti }

  procedure skaityti (var M1, M2, N: integer; var v: virsunes);
    var f: text;
        i: integer;
  begin
    assign (f, PRF);
    reset (f);
    readln (f, M1, M2);
    readln (f, N);
    for i := 1 to N do
      readln (f, v[i].x, v[i].y);
    close (f);
  end; { skaityti }

  procedure rasyti (galima: boolean; kiek: integer; vk1, vk2, ad1, ad2: taskas);
    var f: text;
  begin
    assign (f, RZF);
    rewrite (f);
    if galima
       then begin
              writeln (f, 'PAVYKS');
              writeln (f, kiek);
              writeln (f, vk1.x, ' ', vk1.y, ' ', ad1.x, ' ', ad1.y);
              if kiek=2 then writeln (f, vk2.x, ' ', vk2.y, ' ', ad2.x, ' ', ad2.y);
            end
        else writeln (f, 'NEPAVYKS');
    close (f);
  end; { rasyti }

  var vk, vk1, vk2, ad, ad1, ad2: taskas;
      galima: boolean;
      kiek: integer;
begin
  skaityti (M1, M2, N, v);
  rasti_stac (vk, ad);
  dengti (vk, ad, galima, kiek, vk1, vk2, ad1, ad2);
  rasyti (galima, kiek, vk1, vk2, ad1, ad2);
end.
