#include <bits/stdc++.h>
using namespace std;
bool debug;
const int inf = 1e9 + 5;
const long long INF = (long long)inf * inf;
const int nax = 1e6 + 5;
int n, rekord, d;
char sl[15];
vector<pair<int, int> > w;
int o[nax];
int find(int a) { return a == o[a] ? a : o[a] = find(o[a]); }
void uni(int a, int b) { o[find(a)] = find(b); }
int f(char z) { return int(z - '0'); }
void wczytaj() {
  scanf("%d%d%d", &n, &rekord, &d);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", sl);
    int hh = f(sl[0]) * 10 + f(sl[1]);
    int mm = f(sl[3]) * 10 + f(sl[4]);
    int ss = f(sl[6]) * 10 + f(sl[7]);
    int jeb = ss + 60 * mm + 3600 * hh;
    w.push_back(make_pair(jeb, i));
  }
}
map<int, int> mapka;
int main(int argc, char *argv[]) {
  debug = argc > 1;
  wczytaj();
  multiset<pair<int, int> > s;
  for (int i = 1; i <= n; ++i) o[i] = i;
  bool pyklo = false;
  for (int i = 0; i <= ((int)w.size()) - 1; ++i) {
    pair<int, int> p = w[i];
    int kiedy = p.first;
    int id = p.second;
    while ((!s.empty()) && (*s.begin()).first < kiedy) s.erase(s.begin());
    s.insert(make_pair(kiedy + d - 1, id));
    if (i == (int)w.size() - 1 || w[i + 1].first != w[i].first) {
      if ((int)s.size() == rekord) pyklo = true;
      while ((int)s.size() > rekord) {
        auto it = s.end();
        --it;
        if (it == s.begin()) {
          puts("No solution");
          return 0;
        }
        int memo = (*it).second;
        --it;
        int teraz = (*it).second;
        uni(memo, teraz);
        s.erase(it);
      }
    }
  }
  if ((int)s.size() == rekord) pyklo = true;
  if (!pyklo) {
    puts("No solution");
    return 0;
  }
  for (int i = 1; i <= n; ++i) find(i);
  set<int> dupsko;
  for (int i = 1; i <= n; ++i) dupsko.insert(o[i]);
  int L = 0;
  for (auto a : dupsko) mapka[a] = ++L;
  printf("%d\n", L);
  for (int i = 1; i <= n; ++i) printf("%d\n", mapka[o[i]]);
  return 0;
}
