#include <bits/stdc++.h>
using namespace std;
int n, M, T;
int s[20010];
int num[20010];
deque<int> deq;
int now;
bool ok;
int main() {
  scanf("%d %d %d", &n, &M, &T);
  for (int i = 0; i < (n); i++) {
    int hh, mm, ss;
    scanf("%d:%d:%d", &hh, &mm, &ss);
    --hh;
    --mm;
    --ss;
    s[i] = hh * 3600 + mm * 60 + ss;
    while (deq.size() > 0 && s[deq[0]] + T <= s[i]) {
      deq.pop_front();
    }
    if (deq.size() < M) {
      num[i] = now++;
    } else {
      num[i] = num[deq.back()];
      deq.pop_back();
    }
    deq.push_back(i);
    if (deq.size() == M) ok = 1;
  }
  if (!ok) {
    puts("No solution");
  } else {
    printf("%d\n", now);
    for (int i = 0; i < (n); i++) printf("%d\n", num[i] + 1);
  }
  return 0;
}
