program check;

{$APPTYPE CONSOLE}

uses
  SysUtils, TestLib;

var
  n, m, i, j: Integer;
  a: array [1..210, 1..210] of Integer;
  ans, x1, y1, x2, y2: Integer;
  c: char;

procedure repaintH(q, col : Integer);
var
  i_ : Integer;
begin
  for i_ := 1 to m do
    a[q][i_] := col;
end;

procedure repaintV(q, col : Integer);
var
  i_ : Integer;
begin
  for i_ := 1 to n do
    a[i_][q] := col;
end;

begin
  n := inf.ReadInteger;
  m := inf.ReadInteger;
  for i := 1 to n do
    for j := 1 to m do
      a[i,j] := inf.ReadInteger;
  ans := ouf.ReadInteger;
  if (ans > 2 * (n + m)) and (ans < 0) then
    Quit(_wa, 'Big answer');
  for i := 1 to ans do
  begin
    c := ouf.nextchar;
    while (c <> 'V') and (c <> 'H') do
    begin
      if (c <> ' ') and (ord(c) <> 10) and (ord(c) <> 13) then
        Quit(_wa,'Unknown character');
      c := ouf.nextchar;
    end;
    x1 := ouf.ReadInteger;
    y1 := ouf.ReadInteger;
    x2 := ouf.ReadInteger;
    y2 := ouf.ReadInteger;
    if (x1 < 1) or (x1 > n) or (x2 < 1) or (x2 > n) then
      Quit(_wa, 'Bad x1 or x2');
    if (y1 < 1) or (y1 > m) or (y2 < 1) or (y2 > m) then
      Quit(_wa, 'Bad y1 or y2');
    if (a[x1][y1] <> a[x2][y2]) then
      Quit(_wa, 'a[x1, y1] != a[x2, y2]');
    if (c = 'V') then begin
      if (y1 <> y2) then begin
        Quit(_wa, 'The command is V, but y1 != y2');
      end;  
      repaintV(y1,a[x1][y1])
    end else begin
      if (x1 <> x2) then begin
        Quit(_wa, 'The command is H, but x1 != x2');
      end;  
      repaintH(x1,a[x1][y1]);
    end;
  end;
  ans := a[1][1];
  for i := 1 to n do
    for j := 1 to m do
      if (ans <> a[i][j]) then
        Quit(_wa,'not correct paint');
  Quit(_ok,'accepted');
end.
