#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, T;
  scanf("%d %d %d", &n, &m, &T);
  int max_online = 0;
  int diff = 0;
  std::vector<int> log(n);
  std::vector<int> t(n);
  int j = 0;
  deque<int> a;
  for (int i = 0; i < n; ++i) {
    int hh, mm, ss;
    scanf("%d:%d:%d", &hh, &mm, &ss);
    t[i] = hh * 60 * 60 + mm * 60 + ss;
    while (!a.empty() && a.front() + T - 1 < t[i]) {
      a.pop_front();
    }
    if (a.size() == m) {
      a.back() = t[i];
      log[i] = log[i - 1];
    } else {
      a.push_back(t[i]);
      log[i] = ++diff;
    }
    max_online = max(max_online, int(a.size()));
  }
  if (max_online < m) {
    printf("No solution\n");
  } else {
    printf("%d\n", diff);
    for (int i = 0; i < n; ++i) {
      printf("%d\n", log[i]);
    }
  }
  return 0;
}
