const
   MaxN = 1000100;
   MaxD = 1000100;


var
   inFile, outFile : Text;
   n, d, sol, pos : longint;
   s, p : array[0..MaxN] of longint;
   count : array[0..10] of longint;
   ind, num : array[0..MaxN] of longint;
   a : array[0..MaxD, 0..10] of longint;


procedure Input;
var
   i : longint;
   ch : char;

begin

   assign( inFile, 'sorti.in' );
   reset( inFile );
   readln( inFile, n, d );
   for i := 0 to n - 1 do begin
      read( inFile, ch );
      s[i] := ord( ch ) - 48;
   end;
   close( inFile );

end;


procedure Output;
var
  i : longint;

begin

   assign( outFile, 'sorti.out' );
   rewrite( outFile );
   writeln( outFile, sol );
   for i := 0 to sol - 1 do
      writeln( outFile, ind[ i ], ' ', num[ i ] );
   close( outFile );

end;


procedure Solve;
var
  i, j, number : longint;

begin

   fillchar(count, sizeof(count), 0);
   for i := 0 to n - 1 do
      count[ s[ i ] ] := count[ s[ i ] ] + 1;

   pos := 0;
   for i := 0 to 9 do
      for j := 1 to count[ i ] do begin
         p[ pos ] := i;
         pos := pos + 1;
      end;

   for i := 0 to n - 1 do begin
      a[ i MOD d ][ s[i] ] := a[ i MOD d ][ s[i] ] + 1;
      a[ i MOD d ][ p[i] ] := a[ i MOD d ][ p[i] ] - 1;
   end;

   sol := 0;
   for i := 0 to d - 1 do
      for j := 0 to 9 do
         if (a[i][j] > 0) then sol := sol + a[i][j];

   number := 0;
   for i := 0 to d - 1 do begin
      pos := i;
      for j := 0 to 9 do
         while ( a[i][j] < 0 ) do begin
            if ( a[i][ s[pos] ] > 0 ) then begin
                ind[ number ] := pos + 1;
                num[ number ] := j;
                number := number + 1;
                a[i][j] := a[i][j] + 1;
                a[i][ s[pos] ] := a[i][ s[pos] ] - 1;
            end;
            pos := pos + d;
         end;
   end;

end;


begin

   Input;
   Solve;
   Output;

end.
