{$R+}
uses
  Math;
var
  a: array of String;
  v: array of array of array [-1..1, -1..1] of Integer;
  N, x, y, steps, step, i, dx, dy, t: Integer;
  f: TextFile;
begin
  AssignFile(f, 'input.txt'); Reset(f);

  Read(f, N);
  SetLength(a, N + 1);
  SetLength(v, N + 1, N + 1);
  for x := 1 to N do
    for y := 1 to N do
      for dx := -1 to 1 do
        for dy := -1 to 1 do
          v[x, y, dx, dy] := 0;

  Readln(f, x, y, steps);
  for i := 1 to N do Readln(f, a[i]);
  CloseFile(f);

  dx := 0; dy := -1;
  
  if not InRange(x, 1, N) or (y < 1) then begin
    Inc(y, dy * steps);
    step := steps + 1;
  end
  else if y > N + 1 then begin
    step := Min(y - N, steps + 1);
    Inc(y, dy * (step - 1));
  end
  else
    step := 1;

  while step <= steps do begin
    while
      InRange(x + dx, 1, N) and
      InRange(y + dy, 1, N) and
      (a[y + dy, x + dx] = '#')
    do begin
      t := dy; dy := -dx; dx := t;
    end;
    if not InRange(x + dx, 1, N) or not InRange(y + dy, 1, N) then begin
      Inc(x, dx * (steps - step + 1));
      Inc(y, dy * (steps - step + 1));
      break;
    end;
    Inc(x, dx);
    Inc(y, dy);
    if v[x, y, dx, dy] > 0 then begin
      t := step - v[x, y, dx, dy];
      Inc(step, (steps - step) div t * t);
    end
    else
      v[x, y, dx, dy] := step;
    Inc(step);
  end;

  AssignFile(f, 'output.txt'); Rewrite(f);
  Writeln(f, x, ' ', y);
  CloseFile(f);
end.
