import java.io.*;
import java.util.*;
import java.math.*;

public class cylon_aa {
	public static void main(String[] args) {
		new cylon_aa().run();
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	boolean eof = false;

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			br = new BufferedReader(new FileReader(FNAME + ".in"));
			out = new PrintWriter(FNAME + ".out");
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(566);
		}
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "0";
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	void myAssert(boolean u, String message) {
		if (!u) {
			throw new Error("Assertion failed!!! " + message);
		}
	}

	int inBounds(int x, int l, int r, String name) {
		myAssert(l <= x && x <= r, name + " is not in bounds: " + x
				+ " not in [" + l + ", " + r + "]");
		return x;
	}

	String FNAME = "cylon";

	private void solve() throws IOException {
		int n = inBounds(nextInt(), 1, 100, "n");
		int m = inBounds(nextInt(), 1, 100, "m");
		long[][] a = new long[n + 1][m + 1];
		for (int i = 1; i < a.length; i++) {
			for (int j = 1; j < a[i].length; j++) {
				a[i][j] = inBounds(nextInt(), -1000, 1000, "a[" + i + ", " + j
						+ "]");
			}
		}
		long[][] c = new long[2][2];
		for (int i = 0; i < c.length; i++) {
			for (int j = 0; j < c[i].length; j++) {
				c[i][j] = inBounds(nextInt(), -1, 1, "c[" + (i + 1) + ", "
						+ (j + 1) + "]");
			}
		}
		myAssert(c[1][1] != 0, "c[2, 2] = 0");
		long[][] b = new long[n + 1][m + 1];
		for (int i = 1; i < b.length; i++) {
			for (int j = 1; j < b[i].length; j++) {
				b[i][j] = a[i][j];
				for (int k = 0; k < c.length; k++) {
					for (int l = 0; l < c[k].length; l++) {
						if (k == 1 && l == 1) {
							break;
						}
						b[i][j] -= c[k][l] * b[i + k - 1][j + l - 1];
					}
				}
				if (c[1][1] < 0) {
					b[i][j] = -b[i][j];
				}
			}
		}
		for (int i = 1; i < b.length; i++) {
			for (int j = 1; j < b[i].length; j++) {
				out.print(b[i][j] + " ");
			}
			out.println();
		}
	}
}
