uses
	testlib, sysutils, math;

procedure sort(var x, y: longint);
var
	t: longint;
begin
	if (x > y) then begin
		t := x; x := y; y := t;
	end;
end;

function intersect(x1, y1, x2, y2, x3, y3, x4, y4: integer): boolean;
begin
	sort(x1, x2);
	sort(y1, y2);
	sort(x3, x4);
	sort(y3, y4);

	intersect := false;
	if (x2 < x3) or (x4 < x1) or (y2 < y3) or (y4 < y1) then
		exit;
	intersect := true;
end;

function intersecth(x1, x2, y1, x3, x4, y3: longint): boolean;
begin
	sort(x1, x2);
	sort(x3, x4);

	intersecth := false;

	if (y1 <> y3) or (x2 < x3) or (x4 < x1) then exit;

	intersecth := true;
end;

var
	d, ja, pa, n, i, j: longint;
	x, y: array [1..401] of longint;
	a: array [1..200] of longint;
	u: array [1..200] of boolean;
	found: boolean;

begin
	ja := ans.readlongint;
	pa := ouf.readlongint;

	if pa < ja then
		quit(_wa, format('expected: %d, found: %d', [ja, pa]));

	n := inf.readlongint;

	if pa > n then
		quit(_wa, format('clearly invalid: %d', [pa]));

	for i := 1 to n do begin
		a[i] := inf.readlongint;
	end;

	for i := 1 to 2 * pa do begin
		x[i] := ouf.readlongint;
		y[i] := ouf.readlongint;
	end;
	x[2 * pa + 1] := x[1];
	y[2 * pa + 1] := y[1];

	for i := 1 to 2 * pa do begin
		if i mod 2 = 1 then begin
			if y[i] <> y[i + 1] then
				quit(_wa, format('edge %d is not horizontal', [i]));
		end else begin
			if x[i] <> x[i + 1] then
				quit(_wa, format('edge %d is not vertical', [i]));
		end;
		if (x[i + 1] = x[i]) and (y[i + 1] = y[i]) then
			quit(_wa, format('empty segment %d', [i]));
	end;

	for i := 1 to 2 * pa do begin
		if i mod 2 = 1 then begin
			d := abs(x[i] - x[i + 1]);
			found := false;
			for j := 1 to n do begin
				if not u[j] and (a[j] = d) then begin
					u[j] := true;
					found := true;
					break;
				end;
			end;
			if not found then
				quit(_wa, format('invalid horizontal edge length %d (or too many edges with this length)', [d]));
		end;
	end;

	for i := 1 to pa do
		for j := i + 1 to pa do begin
			if intersecth(x[2 * i - 1], x[2 * i], y[2 * i], x[2 * j - 1], x[2 * j], y[2 * j]) then
				quit(_wa, format('edges %d and %d intersect', [i, j]));
		end;

	for i := 1 to pa do
		for j := i + 1 to pa do begin
			if intersecth(y[2 * i], y[2 * i + 1], x[2 * i], y[2 * j], y[2 * j + 1], x[2 * j]) then
				quit(_wa, format('edges %d and %d intersect', [i, j]));
		end;

	for i := 1 to 2 * pa do 
		for j := i + 1 to 2 * pa do begin
			if (i mod 2) <> (j mod 2) then
    			if intersect(x[i], y[i], x[i + 1], y[i + 1], x[j], y[j], x[j + 1], y[j + 1]) and (abs(i - j) <> 1) and not ((i = 1) and (j = 2 * pa)) then
    				quit(_wa, format('edges %d and %d intersect', [i, j]));
		end;

   	if ja < pa then
		quit(_fail, format('expected: %d, found: %d', [ja, pa]));

	quit(_ok, format('%d segments used', [pa]));
end.