uses
  testlib, SysUtils;

const
  dx : array[1..8] of integer = (-1, -1, -1, 0, 0, 1, 1, 1);
  dy : array[1..8] of integer = (-1, 0, 1, -1, 1, -1, 0, 1);
  imp = 'Impossible';
  exp = ['.', 'h', 'T'];
  MAXN = 50;

var
  n, m, k : integer;
  jf, pf : boolean;
  js, ps : string;

procedure checkstr(q : boolean; s : string; n, num : integer);
var
  i : integer;
begin
  if (length(s) <> n) then begin
    if (q) then begin
      quit(_pe, 'Wrong length of string number ' + IntToStr(num) + ', expected: ' + IntToStr(n) + ', found ' + IntToStr(length(s)));
    end else begin
      quit(_fail, 'Wrong length of string number ' + IntToStr(num) + ' expected: ' + IntToStr(n) + ', found ' + IntToStr(length(s)));
    end;
  end;
  for i := 1 to n do begin
    if (not(s[i] in exp)) then begin
      if (q) then begin
        quit(_pe, 'Wrong character at string number ' + IntToStr(n) + ', position ' + IntToStr(i) + ', found: ' + s[i]);
      end else begin
        quit(_fail, 'Wrong character at string number ' + IntToStr(n) + ', position ' + IntToStr(i) + ', found: ' + s[i]);
      end;
    end;
  end;
end;

procedure check(var f : InStream; s : string; n, m, k : integer; b : boolean);
var
  tab : array[1..MAXN, 1..MAXN] of char;
  i, j, kk, l, x, y : integer;
  found : boolean;
begin
  checkstr(b, s, m, 1);
  for j := 1 to m do begin
    tab[1][j] := s[j];
  end;
  for i := 2 to n do begin
    s := f.readstring;
    checkstr(b, s, m, i);
    for j := 1 to m do begin
      tab[i][j] := s[j];
    end;
  end;
  kk := 0;
  for i := 1 to n do begin
    for j := 1 to m do begin
      if (tab[i][j] = 'h') then begin
        found := false;
        for l := 1 to 8 do begin
          x := i + dx[l];
          y := j + dy[l];
          if (x < 1) or (y < 1) or (x > n) or (y > m) then begin
            continue;
          end;
          if (tab[x][y] = 'T') then begin
            found := true;
            break;
          end;
        end;
        if (not(found)) then begin
          if (b) then begin
            quit(_wa, 'No table near chair at position: (' + IntToStr(i) + ', ' + IntToStr(j) + ')');
          end else begin
            quit(_fail, 'No table near chair at position: (' + IntToStr(i) + ', ' + IntToStr(j) + ')');
          end;
        end;
        kk := kk + 1;
      end;
    end;
  end;
  if (k <> kk) then begin
    if (b) then begin
      quit(_wa, 'Wrong number of chairs, expected: ' + IntToStr(k) + ', found: ' + IntToStr(kk));
    end else begin
      quit(_fail, 'Wrong number of chairs, expected: ' + IntToStr(k) + ', found: ' + IntToStr(kk));
    end;
  end;
end;

begin
  n := inf.readinteger;
  m := inf.readinteger;
  k := inf.readinteger;
  js := ans.readstring;
  ps := ouf.readstring;
  jf := false;
  pf := false;
  if (js <> imp) then begin
    check(ans, js, n, m, k, false);
    jf := true;
  end;
  if (ps <> imp) then begin
    check(ouf, ps, n, m, k, true);
    pf := true;
  end;

  if (jf) and not(pf) then begin
    quit(_wa, 'Contestant did not find a solution, but it exists');
  end;
  if not(jf) and (pf) then begin
    quit(_fail, 'Contestant found a solution, but jury did not!!!');
  end;
  if not(jf) and not(pf) then begin
    quit(_ok, 'No solution');
  end;
  quit(_ok, 'Solution found');
end.

