{$R+}

uses
  Math, SysUtils;

var
  finp, fout, fans: TextFile;
  i, j, k, m, ma, x, y, N: Integer;
  A: array of array of Integer;
begin
  AssignFile(finp, ParamStr(1)); 
  AssignFile(fout, ParamStr(2)); 
  AssignFile(fans, ParamStr(3)); 

  try 
    {$I-}
    Reset(finp);
    Reset(fout);
    Reset(fans);
    {$I+}
    if IOResult <> 0 then Abort;

    if Eof(fout) then Halt(2);
    Read(fout, x, y, m);
    Read(finp, N);
    SetLength(A, N + 1, N + 1);
    for i := 1 to N do
      for j := 1 to N do
        Read(finp, A[i, j]);
    Dec(m);
    for k := 0 to m do begin
      if
        (A[x + k, y] <> A[x + k, y + m]) or
        (A[x, y + k] <> A[x + m, y + k])
      then begin
        Write('Not a tile');
        Halt(1);
      end;
    end;
    {$HINTS OFF}
    Read(fans, x, y, ma);
    Inc(m);
    if ma = m then Halt(0)
    else if m < ma then begin Write('Not optimal'); Halt(1); end
    else begin Write('Unbelivable!'); Halt(3); end;
  except
    Halt(2);
  end;
  CloseFile(finp);
  CloseFile(fout);
  CloseFile(fans);
end.
