uses
	testlib, SysUtils;
const
	DAY_LENGTH = 24 * 60;

function parseDate(const s : string) : longint;
begin
	if not((s[1] in ['0'..'9']) and (s[2] in ['0'..'9']) and (s[3] = ':') and (s[4] in ['0'..'9']) and (s[5] in ['0'..'9'])) then
		quit(_pe, 'Incorrect date format' + s);
		result := strToInt(copy(s, 1, 2)) * 60 + strToInt(copy(s, 4, 2));
end;


var
	ja, pa: string;
	n, l, r, i, j, a, b, e, cnt: longint;
	u : array[0..DAY_LENGTH - 1] of longint;
	s : string;
begin
	a := inf.ReadInteger * 60;
	b := inf.ReadInteger * 60;
	n := inf.ReadInteger;

	inf.ReadString();

	for i := 1 to n do begin
		s := inf.ReadString();
		l := parseDate(copy(s, 1, 5));
		r := parseDate(copy(s, 7, 5));
		j := l;
		
		while (true) do begin
			u[j] := -i;
			if (j = r) then break;
			j := (j + 1) mod DAY_LENGTH;
		end;
	end;

	pa := ouf.ReadString;
	if (pa <> 'Yes') and (pa <> 'No') then quit(_pe, 'Incorrect answer: ' + pa);

	if (pa = 'Yes') then begin
		n := ouf.ReadLongint;
		if (n <= 0) then quit(_pe, 'Incorrect number of sleeping intervals: ' + intToStr(n));
		ouf.readString();
		for i := 1 to n do begin
			s := ouf.ReadString();
			if (length(s) <> 11) or (s[6] <> '-') then quit(_pe, 'Incorrect date format: ' + s);
			l := parseDate(copy(s, 1, 5));
			r := parseDate(copy(s, 7, 5));
			j := l;
			cnt := 0;
			while (true) do begin
				if (u[j] <> 0) then begin
					if (u[j] < 0) then
						quit(_wa, 'Interval ' + inttostr(i) + ' intersects with task ' + inttostr(-u[i]))
					else
						quit(_wa, 'Interval ' + inttostr(i) + ' intersects with interval' + inttostr(u[i]))
				end;
				inc(cnt);
				u[j] := i;
				if (j = r) then break;
				j := (j + 1) mod DAY_LENGTH;
			end;
			if (cnt < a) then quit(_wa, 'Undersleeping at interval #' + inttostr(i) + '( ' + s + ')');
		end;

		e := -1;
		for i := 0 to DAY_LENGTH - 1 do begin
			if (u[(i + DAY_LENGTH - 1) mod DAY_LENGTH] <= 0) and (u[i] > 0) then begin
				e := i;
				break;
			end;
		end;

		i := e;
		cnt := b;
		repeat
			if (u[i] <= 0) then begin
				dec(cnt);
			end else begin
				if (cnt < 0) then 
					quit(_wa, 'Cat didn''t sleep enough at ' + format('%.2d:%.2d', [i div 60, i mod 60]));
				cnt := b;
			end;
			i := (i + 1) mod DAY_LENGTH;
		until i = e;
		if (cnt < 0) then 
			quit(_wa, 'Cat didn''t sleep enough at ' + format('%.2d:%.2d', [i div 60, i mod 60]));
 	end;

 	ja := ans.readString;
	if (ja = pa) then quit(_ok, 'Ok: ' + ja);
	if (pa = 'No') then quit(_wa, 'Yes expected');
	if (pa = 'Yes') then quit(_fail, 'Contestant found a solution');

end.
