const
  maxn = 100;
var
  a, ans : array[0..maxn, 0..maxn] of int64;
  c : array[1..2, 1..2] of integer;
  n, m, i, j, di, dj : integer;
begin
  reset(input, 'cylon.in');
  rewrite(output, 'cylon.out');
  read(n, m);
  assert((1 <= n) and (n <= maxn));
  assert((1 <= m) and (m <= maxn));
  ans[0][0] := 0;
  for i := 1 to n do begin
    ans[i][0] := 0;
    ans[0][i] := 0;
    for j := 1 to m do begin
      read(a[i][j]);
      assert(abs(a[i][j]) <= 1000);
    end;
  end;
  for i := 1 to 2 do begin
    for j := 1 to 2 do begin
      read(c[i][j]);
      assert(abs(c[i][j]) <= 1);
    end;
  end;
  assert(c[2][2] <> 0);
  for i := 1 to n do begin
    for j := 1 to m do begin
      ans[i][j] := a[i][j];
      for di := 1 to 2 do begin
        for dj := 1 to 2 do begin
          if (di + dj < 4) then begin
            ans[i][j] := ans[i][j] - c[di][dj] * ans[i + di - 2][j + dj - 2];
          end;
        end;
      end;
      ans[i][j] := ans[i][j] * c[2][2];
    end;
  end;
  for i := 1 to n do begin
    for j := 1 to m do begin
      write(ans[i][j], ' ');
    end;
    writeln;
  end;
end.