#include <bits/stdc++.h>
using namespace std;
const int mod = int(1e7) + 7;
int a[100010], ans[100010] = {0};
int main() {
  bool ok = false;
  set<pair<int, int> > s;
  int n, m, T, hh, mm, ss, l = 1;
  scanf("%d%d%d", &n, &m, &T);
  for (int i = 0; i < n; i++) {
    scanf("%d:%d:%d", &hh, &mm, &ss);
    a[i] = hh * 3600 + mm * 60 + ss;
  }
  for (int i = 0; i < n; i++) {
    while (!s.empty() && (*s.begin()).first <= a[i]) {
      s.erase(s.begin());
    }
    if (int((s).size()) == m) {
      set<pair<int, int> >::iterator it = s.end();
      it--;
      ans[i] = (*it).second;
      s.erase(it);
    } else {
      ans[i] = l++;
    }
    s.insert(make_pair((a[i] + T), (ans[i])));
    if (int((s).size()) == m) ok = true;
  }
  if (!ok)
    puts("No solution");
  else {
    printf("%d\n", l - 1);
    for (int i = 0; i < n; i++) printf("%d\n", ans[i]);
  }
  return 0;
}
