{$apptype console}
uses SysUtils;

function parseDate(const s : string) : longint;
begin
	assert(length(s) = 5);
	assert(s[1] in ['0'..'9']);
	assert(s[2] in ['0'..'9']);
	assert(s[3] = ':');
	assert(s[4] in ['0'..'9']);
	assert(s[5] in ['0'..'9']);
	result := strToInt(copy(s, 1, 2)) * 60 + strToInt(copy(s, 4, 2));
end;

function conv(i : longint) : string;
begin
	result := intToStr(i);
	if (i < 10) then
		result := '0' + intToStr(i);
end;

function getDate(i : longint) : string;
begin
	result := conv(i div 60) + ':' + conv(i mod 60);
end;

procedure No;
begin
  writeln('No');
  halt;
end;

const
	DAY_LENGTH = 24 * 60;

var
	a, b, n, l, r, i, j, e, cnt, ans : longint;
	s : string;
	u : array[0..DAY_LENGTH - 1] of boolean;

begin
	reset(input, 'cat.in');
	rewrite(output, 'cat.out');
	read(a, b);
	assert((1 <= a) and (a <= 24));
	assert((1 <= b) and (b <= 24));
	a := a * 60;
	b := b * 60;
	readln(n);
	assert((1 <= n) and (n <= 20));

	for i := 1 to n do begin
		readln(s);
		assert(length(s) = 11);
		l := parseDate(copy(s, 1, 5));
		r := parseDate(copy(s, 7, 5));
		assert(l <> r);
		j := l;
		while (true) do begin
			assert(not u[j]);
			u[j] := true;
			if (j = r) then break;
			j := (j + 1) mod DAY_LENGTH;
		end;
	end;

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

  if (e = -1) then No;

	i := e;
	cnt := 0;
	repeat
		if (u[i]) then begin
			if (cnt < a) then begin
				j := i;
				repeat
					u[j] := true;
					j := (j + DAY_LENGTH - 1) mod DAY_LENGTH;
				until u[j];
			end;
			cnt := 0;
		end else begin
			inc(cnt);
		end;
		i := (i + 1) mod DAY_LENGTH;
	until i = e;

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

	cnt := 1;
	ans := 0;
    i := e;
	repeat
		if (u[i]) then begin
			inc(cnt);
			if (cnt > b) then No;
		end else begin
			if (cnt > 0) then inc(ans);
			cnt := 0;
		end;
		i := (i + 1) mod DAY_LENGTH;
	until i = e;

	if (cnt > b) then No;

	writeln('Yes');
	writeln(ans);


	l := -1;
	repeat
		if (u[i]) then begin
			if (l >= 0) then writeln(getDate(l),'-',getDate((i + DAY_LENGTH - 1) mod DAY_LENGTH));
			l := -1;
		end else begin	
			if (l = -1) then l := i;
		end;
		i := (i + 1) mod DAY_LENGTH;
	until i = e;
end.