{$M 65000,0,655360}

{$R-,Q-,S-,I-}

program Car_Problem;

const
  name1       =        'car.in';
  name2       =        'car.out';
  maxN        =        20000;
  maxM        =        52;

type
  Tcar        =        array[1..maxN] of byte;

var
  N, M, W     :        integer;
  car         :        Tcar;
  car2        :        ^Tcar;
  next        :        array[1..maxN] of integer;
  R           :        integer;
  ouf         :        text;
  Range       :        array[1..maxM+1] of integer;

procedure init;
var inf : text;
    i   : integer;
begin
  assign(inf, name1);
  reset(inf);
  readln(inf, N, M, W);
  for i := 1 to N do read(inf, car[i]);
  close(inf);
  fillchar(range, sizeof(range), 0);
  for i := 1 to N do inc(range[ car[i] + 1 ]);
  range[1] := 1;
  for i := 2 to M+1 do
    range[i] := range[i-1] + range[i];
end;

procedure TryOnce(print : boolean);
var Head, Tail : array[1..maxM, 1..maxM] of integer;
    i, j, Si, i2, j2, jj   : integer;
    x, y       : integer;
    len, thisC, fl : integer;
    thisOut    : array[1..maxM, 1..2] of integer;

    circle     : array[1..maxM] of integer;
    Sign       : array[1..maxM] of integer;
    ok         : array[1..maxM] of boolean;

    quit       : boolean;

  procedure InLink(t, Si : integer);
  begin
    if head[Si, car[t]] = 0
      then begin
             head[Si, car[t]] := t;
             tail[Si, car[t]] := t;
             next[t] := 0;
           end
      else begin
             next[ tail[Si, car[t]] ] := t;
             tail[Si, car[t]] := t;
             next[t] := 0;
           end;
  end;

  procedure CircleMove;
  var i : integer;
      tempSi, tempNe, Si : integer;
  begin
    fl := 1;
    for i := 1 to len-1 do
      if car[ circle[len] ] = sign[i] then fl := i;
    circle[len+1] := circle[fl];
    sign[len+1] := sign[fl];

    tempSi := car[ circle[fl] ];
    tempNe := next[ circle[fl] ];
    for i := len downto fl do
      begin
        if i = fl then Si := tempSi
          else Si := car[ circle[i] ];
        head[ Sign[i], Si ] := next[ circle[i] ];
        if i = fl then head[ Sign[i], Si ] := TempNe;
        car[circle[i+1]] := Si;
        InLink(circle[i+1], sign[i+1]);
        inc(thisC);
        thisOut[thisC, 1] := circle[i];
        thisOut[thisC, 2] := circle[i+1];
      end;
  end;

begin
  {make links}
  fillchar(head, sizeof(head), 0);
  fillchar(tail, sizeof(tail), 0);
  fillchar(next, sizeof(next), 0);
  Si := 1;
  for i := 1 to N do
    begin
      while Range[Si+1] <= i do inc(Si);
      InLink(i, Si);
    end;

  {each turn}
  repeat
    thisC := 0;
    while thisC < W-1 do
      begin
        quit := true;
        for i := 1 to M do
          for j := 1 to M do
            if (i <> j) and (Head[i, j] <> 0) then
              begin
                quit := false;
                len := 1;
                circle[len] := Head[i, j];
                sign[len] := i;
                x := Head[i, j];
                fillchar(ok, sizeof(ok), true);

                ok[i] := false;
                i2 := i;
                j2 := j;
                ok[j2] := false;
                repeat
                  i2 := j2;
                  j2 := 1;
                  while (i2 = j2) or (Head[i2, j2] = 0) do inc(j2);
                  inc(len);
                  sign[len] := i2;
                  circle[len] := Head[i2, j2];
                  if not ok[j2] then break;
                  ok[j2] := false;
                until thisC + len = W;
                CircleMove;
                if thisC >= W-1 then
                  begin
                    i := M;
                    j := M;
                  end;
              end;
        if quit then break;
      end;
    if thisC > 0 then
      begin
        inc(R);
        if print then
          begin
            write(ouf, thisC);
            for i := 1 to thisC do
              write(ouf, ' ', thisOut[i, 1], ' ', thisOut[i, 2]);
            writeln(ouf);
          end;
        thisC := 0;
      end;
  until quit;
end;

begin
  init;
  new(car2);
  car2^ := car;

  R := 0;
  TryOnce(false);

  assign(ouf, name2);
  rewrite(ouf);
  writeln(ouf, R);

  car := car2^;
  TryOnce(true);

  close(ouf);
end.
