#include <bits/stdc++.h>
int a[20009];
int ans[20009];
int last[20009];
int main() {
  int n, m, t;
  scanf("%d %d %d", &n, &m, &t);
  for (int i = 0; i < n; i++) {
    int h, m, s;
    scanf("%d:%d:%d", &h, &m, &s);
    a[i] = 60 * 60 * h + 60 * m + s;
  }
  ans[0] = 1;
  last[1] = 0;
  int r = 1, maxOnline = 1, online = 1;
  for (int i = 1, j = 0; i < n; i++) {
    while (a[j] + t <= a[i]) {
      if (last[ans[j]] == j) online--;
      j++;
    }
    if (online == m) {
      ans[i] = ans[i - 1];
    } else {
      r++;
      ans[i] = r;
      online++;
      if (maxOnline < online) maxOnline = online;
    }
    last[ans[i]] = i;
  }
  if (maxOnline < m) {
    printf("No solution");
  } else {
    printf("%d\n", r);
    for (int i = 0; i < n; i++) printf("%d\n", ans[i]);
  }
}
