#include <bits/stdc++.h>
using namespace std;
int N, M, T;
pair<int, int> times[20010];
int ids[20010];
int pids[20010];
int online = 0;
int ocount[20010];
void add(int p) {
  if (ocount[p] == 0) online++;
  ocount[p]++;
}
void remove(int p) {
  if (ocount[p] == 1) online--;
  ocount[p]--;
  assert(ocount[p] >= 0);
}
int main() {
  scanf("%d", &(N));
  scanf("%d", &(M));
  scanf("%d", &(T));
  for (int i = (0); i < (N); i++) {
    int h, m, s;
    scanf("%d:%d:%d", &h, &m, &s);
    m += h * 60;
    s += m * 60;
    times[i] = {s, i};
  }
  sort(times, times + N);
  int pos = 0;
  int R = 0;
  bool ok = false;
  for (int i = (0); i < (N); i++) {
    while (pos < i && times[i].first - times[pos].first >= T)
      remove(ids[pos++]);
    if (online == M)
      ids[i] = ids[i - 1];
    else
      ids[i] = ++R;
    add(ids[i]);
    if (online == M) ok = true;
  }
  if (!ok) {
    printf("No solution\n");
  } else {
    for (int i = (0); i < (N); i++) pids[times[i].second] = ids[i];
    printf("%d\n", R);
    for (int i = (0); i < (N); i++) printf("%d\n", pids[i]);
  }
}
