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

public class digits_ia implements Runnable {

	private BufferedReader in;
	private PrintWriter out;

	public void run() {
		try {
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private void solve() throws Exception {
		Locale.setDefault(Locale.US);
		in = new BufferedReader(new FileReader("digits.in"));
		out = new PrintWriter("digits.out");
		
		String str = in.readLine();
		StringTokenizer st = new StringTokenizer(str);
		int k = Integer.parseInt(st.nextToken());
		assertRange(k, 1, 100);
		int d = Integer.parseInt(st.nextToken());
		assertRange(d, 1, 500);
		myAssert(str.equals(k + " " + d));
		
		str = in.readLine();
		st = new StringTokenizer(str);
		int w = Integer.parseInt(st.nextToken());
		assertRange(w, 1, 10);
		int h = Integer.parseInt(st.nextToken());
		assertRange(h, 1, 10);
		myAssert(str.equals(w + " " + h));
		
		str = in.readLine();
		myAssert(str.equals(str.trim()));
		int n = Integer.parseInt(str);
		assertRange(n, 1, 100);
		
		int[] x1 = new int[n];
		int[] x2 = new int[n];
		int[] y1 = new int[n];
		int[] y2 = new int[n];
		int[] s = new int[n];
		int[] dx = new int[n];
		int[] dy = new int[n];
		
		for (int i = 0; i < n; i++) {
			str = in.readLine();
			st = new StringTokenizer(str);
			x1[i] = Integer.parseInt(st.nextToken()); 
			y1[i] = Integer.parseInt(st.nextToken()); 
			x2[i] = Integer.parseInt(st.nextToken()); 
			y2[i] = Integer.parseInt(st.nextToken()); 
			assertRange(x1[i], 0, w - 1);
			assertRange(x2[i], 0, w - 1);
			assertRange(y1[i], 0, h - 1);
			assertRange(y2[i], 0, h - 1);
			myAssert((x1[i] != x2[i]) || (y1[i] != y2[i]));
			int sx = Math.abs(x1[i] - x2[i]);
			int sy = Math.abs(y1[i] - y2[i]);
			myAssert((sx == sy) || (x1[i] == x2[i]) || (y1[i] == y2[i]));
			s[i] = Math.max(sx, sy);
			if (x2[i] > x1[i]) {
				dx[i] = 1;
			} else if (x2[i] < x1[i]) {
				dx[i] = -1;
			} else {
				dx[i] = 0;
			}
			if (y2[i] > y1[i]) {
				dy[i] = 1;
			} else if (y2[i] < y1[i]) {
				dy[i] = -1;
			} else {
				dy[i] = 0;
			}
		}
		myAssert(in.readLine() == null);
		
		int hh = (h - 1) * k + 1;
		int ww = (w - 1) * k + 1;
		int[][] a = new int[hh][ww];
		
		int b = 0;
		int e = 0;
		int[] qx = new int[ww * hh];
		int[] qy = new int[ww * hh];
		
		for (int i = 0; i < n; i++) {
			int x = x1[i] * k;
			int y = y1[i] * k;
			for (int j = 0; j <= s[i] * k; j++) {
				if (a[y][x] != d) {
					a[y][x] = d;
					qx[e] = x;
					qy[e] = y;
					e++;
				}
				x += dx[i];
				y += dy[i];
			}
		}
		
		final int[] xx = {0, 1, 0, -1};
		final int[] yy = {1, 0, -1, 0};
		
		while (b < e) {
			int x = qx[b];
			int y = qy[b];
			b++;
			for (int z = 0; z < 4; z++) {
				int xn = x + xx[z];
				int yn = y + yy[z];
				if ((xn >= 0) && (xn < ww) && (yn >= 0) && (yn < hh)) {
					if (a[yn][xn] < a[y][x] - 1) {
						a[yn][xn] = a[y][x] - 1;
						qx[e] = xn;
						qy[e] = yn;
						e++;
					}
				}				
			}
		}
		
		for (int i = 0; i < hh; i++) {
			for (int j = 0; j < ww; j++) {
				out.print((a[i][j] > 0) ? '*' : '.');
			}
			out.println();
		}
		
		
		in.close();
		out.close();
	}

	private void assertRange(int a, int l, int h) {
		myAssert((l <= a) && (a <= h));
	}

	private void myAssert(boolean b) {
		String msg = "ERROR IN TEST!!!";
		if (!b) {
			out.println(msg);
			System.out.println(msg);
			out.close();
			throw new Error(msg);
		}
	}

	public static void main(String[] args) {
		new Thread(new digits_ia()).start();

	}

}
