#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
  freopen("cat.in", "r", stdin);
  freopen("cat.out", "w", stdout);

  int a, b, n;
  scanf("%d%d", &a, &b);
  a *= 60, b *= 60;
  scanf("%d", &n);
  int *st = new int[n * 2 + 1], *en = new int[n * 2 + 1];
  int *ansSt = new int[n * 2 + 3], *ansEn = new int[n * 2 + 3];
  for (int i = 0; i < n; i++)
  {
    int h1, m1, h2, m2;
    scanf("%d:%d-%d:%d", &h1, &m1, &h2, &m2);
    int t1 = h1 * 60 + m1, t2 = h2 * 60 + m2 + 1;
    if (t2 <= t1)
    {
      st[i] = t1, en[i] = 24 * 60;
      i++, n++;
      st[i] = 0, en[i] = t2;
    }
    else
      st[i] = t1, en[i] = t2;
  }
  sort(st, st + n);
  sort(en, en + n);
  st[n] = st[0] + 24 * 60;
  int k = 0;
  for (int i = 0; i < n; i++)
    if (st[i + 1] - en[i] >= a)
    {
      ansSt[k] = en[i];
      ansEn[k] = st[i + 1];
      k++;
    }
  ansSt[k] = ansEn[0] + 24 * 60;
  bool good = k > 0;
  for (int i = 0; i < k; i++)
    if (ansSt[i + 1] - ansEn[i] > b)
      good = false, i = k;
  if (!good)
    puts("No");
  else
  {
    puts("Yes");
    printf("%d\n", k);
    for (int i = 0; i < k; i++)
    {
      ansSt[i] = ansSt[i] % (24 * 60);
      ansEn[i] = (ansEn[i] - 1) % (24 * 60);
      int h1 = ansSt[i] / 60, m1 = ansSt[i] % 60;
      int h2 = ansEn[i] / 60, m2 = ansEn[i] % 60;
      printf("%02d:%02d-%02d:%02d\n", h1, m1, h2, m2);
    }
  }

  return 0;
}

