{$apptype console}
{$o-,r+,q+}
uses
  sysutils, math;

type
  int = longint;

const
  maxn = 250;

var
  tnum : int;
  n, m : int;
  f : array[1..maxn, 1..maxn] of char;

function charXor(c1, c2 : char) : char;
begin
  if (c1 = '.') and (c2 = '.') then result := '.';
  if (c1 = '*') and (c2 = '*') then result := '.';
  if (c1 = '*') and (c2 = '.') then result := '*';
  if (c1 = '.') and (c2 = '*') then result := '*';
end;

procedure writeTest();
var
  fname : string;
  i, j : int;
begin
  inc(tnum);
  fname := inttostr(tnum);
  while (length(fname) < 2) do fname := '0' + fname;

  rewrite(output, fname);

  writeln(n, ' ', m);
  for i := 1 to n do
  begin
    for j := 1 to m do
    begin
      write(f[i][j]);
    end;
    writeln;
  end;

  close(output);
end;

procedure readTest();
var
  str : string;
  i, j : int;
  ch : char;
begin
  fillchar(f, sizeof(f), 0);
  readln(n, m);
  for i := 1 to n do
  begin
    readln(str);
    str := trim(str);
    assert(length(str) = m);
    for j := 1 to m do
    begin
      ch := str[j];
      assert(ch in ['.', '*', '?']);
      f[i][j] := ch;
    end;
  end;
end;

function inv(ch : char) : char;
begin
  if ch = '.' then result := '*';
  if ch = '*' then result := '.';
  if ch = '?' then result := '?';
end;

procedure genChessBoard(cs : int; sr, sc : int; nn, mm : int; color : int);
var
  i, j : int;
  cc : int;
  chr : char;
  col, row : int;
begin
  n := nn;
  m := mm;
  for i := 0 to n - 1 do
  begin
    for j := 0 to m - 1 do
    begin
      col := (sc + j) div cs;
      row := (sr + i) div cs;
      cc := (color + col + row) mod 2;
      chr := '.';
      if (cc = 1) then chr := '*';
      f[i + 1][j + 1] := chr;    
    end;
  end;
end;

procedure xorChessBoard(cs : int; sr, sc : int; nn, mm : int; color : int);
var
  i, j : int;
  cc : int;
  chr : char;
  col, row : int;
begin
  n := nn;
  m := mm;
  for i := 0 to n - 1 do
  begin
    for j := 0 to m - 1 do
    begin
      col := (sc + j) div cs;
      row := (sr + i) div cs;
      cc := (color + col + row) mod 2;
      chr := '.';
      if (cc = 1) then chr := '*';
      f[i + 1][j + 1] := charXor(chr, f[i + 1][j + 1]);    
    end;
  end;
end;

procedure randomInv(cnt : int);
var
  i : int;
  r, c : int;
begin
  for i := 1 to cnt do
  begin
    r := random(n) + 1;
    c := random(m) + 1;
    f[r][c] := inv(f[r][c]);
  end;  
end;

procedure randomGrey(cnt : int);
var
  i : int;
  r, c : int;
begin
  for i := 1 to cnt do
  begin
    r := random(n) + 1;
    c := random(m) + 1;
    f[r][c] := '?';
  end;  
end;

procedure genAllGrey(nn, mm : int);
var
  i, j : int;
begin
  n := nn;
  m := mm;
  for i := 1 to n do
  begin
    for j := 1 to m do
    begin  
      f[i][j] := '?';
    end;
  end;
end;
procedure genAllBlack(nn, mm : int);
var
  i, j : int;
begin
  n := nn;
  m := mm;
  for i := 1 to n do
  begin
    for j := 1 to m do
    begin  
      f[i][j] := '*';
    end;
  end;
end;

procedure genAllWhite(nn, mm : int);
var
  i, j : int;
begin
  n := nn;
  m := mm;
  for i := 1 to n do
  begin
    for j := 1 to m do
    begin  
      f[i][j] := '.';
    end;
  end;
end;

var
  i : int;

begin
  randseed := 4372389;
 
  tnum := 0;

  reset(input, 'small_tests.lst');
  while not eof(input) do
  begin
    readTest();
    writeTest();
  end;

  genChessBoard(2, 1, 1, 8, 8, 0);
  randomGrey(10);
  writeTest();

  genChessBoard(100, 0, 0, maxn, maxn, 1);
  randomGrey(maxn * maxn div 4);
  writeTest();

  genChessBoard(100, 0, 0, maxn, maxn, 1);
  randomInv(2);
  writeTest();

  genChessBoard(100, 0, 0, maxn, maxn, 1);
  randomInv(2);
  randomGrey(1000);
  writeTest();

  genChessBoard(100, 0, 0, maxn, maxn, 0);
  randomGrey(maxn * maxn div 4);
  writeTest();

  genChessBoard(100, 0, 0, maxn, maxn, 0);
  randomInv(2);
  writeTest();

  genChessBoard(100, 0, 0, maxn, maxn, 0);
  randomInv(2);
  randomGrey(1000);
  writeTest();

  genAllGrey(maxn, maxn); 
  writeTest();

  genAllBlack(maxn, maxn); 
  writeTest();

  genAllWhite(maxn, maxn); 
  writeTest();

  genAllGrey(maxn - 1, maxn); 
  writeTest();

  genAllBlack(maxn - 1, maxn); 
  writeTest();

  genAllWhite(maxn - 1, maxn); 
  writeTest();
            
  genAllGrey(maxn, maxn - 1); 
  writeTest();

  genAllBlack(maxn, maxn - 1); 
  writeTest();

  genAllWhite(maxn, maxn - 1); 
  writeTest();

  genChessBoard(maxn, maxn div 2, maxn div 2, maxn, maxn, 0);
  writeTest();

  genChessBoard(maxn, maxn div 2, maxn div 2, maxn, maxn, 0);
  randomGrey(10000);
  writeTest();

  genChessBoard(maxn, maxn div 2, maxn div 2, maxn, maxn, 0);
  randomInv(1);
  writeTest();

  for i := 1 to 15 do
  begin
    n := 1 + random(maxn);
    m := 1 + random(maxn);
    genChessBoard(1 + random(maxn), random(n), random(m), n, m, random(2));
    randomGrey(random(1000));
    writeTest();
  end;

  for i := 1 to 15 do
  begin
    n := 1 + random(maxn);
    m := 1 + random(maxn);
    genChessBoard(1 + random(maxn), random(n), random(m), n, m, random(2));
    randomInv(random(1000));
    writeTest();
  end;

  for i := 1 to 10 do
  begin
    n := 1 + random(maxn);
    m := 1 + random(maxn);
    genChessBoard(1 + random(maxn), random(n), random(m), n, m, random(2));
    xorChessBoard(1 + random(maxn), random(n), random(m), n, m, random(2));
    randomGrey(random(1000));
    writeTest();
  end;

end.