#include <bits/stdc++.h>
using namespace std;
const int N = 20005, M = 86410;
int n, m, t, en[N], ans[N], dep, col;
int head, tail;
int main() {
  scanf("%d%d%d", &n, &m, &t);
  int tim;
  head = tail = col = dep = 0;
  bool done = 0;
  for (int hh, mm, ss, i = 0; i < n; i++) {
    scanf("%d:%d:%d", &hh, &mm, &ss);
    tim = hh * 3600 + mm * 60 + ss;
    while (head < tail && en[head] <= tim) {
      ++head;
      --dep;
    }
    if (dep < m) {
      en[tail++] = tim + t;
      ans[i] = ++col;
      dep++;
    } else {
      ans[i] = col;
      en[tail - 1] = tim + t;
    }
    if (dep == m) done = 1;
  }
  if (!done)
    printf("No solution\n");
  else {
    printf("%d\n", col);
    for (int i = 0; i < n; i++) printf("%d\n", ans[i]);
  }
  return 0;
}
