#include <bits/stdc++.h>
using namespace std;
using namespace std;
int n, m, t;
char s[100];
int qk[20514];
int qi[20514];
int qs, qe;
int ds[20514];
int fi(int k) { return ds[k] == k ? ds[k] : ds[k] = fi(ds[k]); }
void un(int a, int b) { ds[fi(b)] = fi(a); }
map<int, int> mp;
void sol() {
  scanf("%d %d", &(m), &(t));
  qs = qe = 0;
  int flag = 0;
  for (int i = 0; i < n; i++) ds[i] = i;
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    for (int j = 0; s[j]; j++) s[j] -= '0';
    int st =
        ((s[0] * 10 + s[1]) * 60 + s[3] * 10 + s[4]) * 60 + s[6] * 10 + s[7];
    for (; qe - qs && qk[qs] + t - 1 < st; qs++)
      ;
    if (qe - qs < m) {
      qk[qe] = st;
      qi[qe] = i;
      qe++;
    } else {
      un(qi[qe - 1], i);
      qk[qe - 1] = st;
    }
    if (qe - qs == m) flag = 1;
  }
  if (flag == 0) {
    puts("No solution");
    return;
  }
  int id = 1;
  mp.clear();
  for (int i = 0; i < n; i++) {
    int tmp = fi(i);
    if (mp[tmp] == 0) {
      mp[tmp] = id++;
    }
  }
  printf("%d\n", ((int)mp.size()));
  for (int i = 0; i < n; i++) {
    int tmp = fi(i);
    printf("%d\n", mp[tmp]);
  }
}
int main() {
  while (scanf("%d", &(n)) != EOF) sol();
  return 0;
}
