#include <bits/stdc++.h>
using namespace std;
const int N = 20001;
vector<pair<pair<int, int>, int> > Clock;
int calc(int hh, int mm, int ss) { return hh * 3600 + mm * 60 + ss; }
int answer[N], cnt[N];
int main() {
  int n, M, T;
  scanf("%d%d%d", &n, &M, &T);
  for (int i = 0; i < n; i++) {
    int hh, mm, ss;
    scanf("%2d:%2d:%2d", &hh, &mm, &ss);
    Clock.push_back(make_pair(make_pair(calc(hh, mm, ss), -1), i));
    Clock.push_back(make_pair(make_pair(calc(hh, mm, ss) + T - 1, 1), i));
  }
  sort(Clock.begin(), Clock.end());
  int now = 0, tot = 0, can = 0;
  for (int i = 0; i < 2 * n; i++) {
    pair<pair<int, int>, int> u = Clock[i];
    if (u.first.second == -1) {
      if (now < M) {
        answer[u.second] = ++tot;
        now++;
      }
      if (now >= M) {
        can = 1;
        answer[u.second] = tot;
      }
      cnt[tot]++;
    } else {
      cnt[answer[u.second]]--;
      if (cnt[answer[u.second]] == 0) now--;
    }
  }
  if (can) {
    printf("%d\n", tot);
    for (int i = 0; i < n; i++) printf("%d\n", answer[i]);
  } else
    puts("No solution");
  return 0;
}
