#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
string const toString(T const &x) {
  return (ostringstream() << x).str();
}
int const UNDEF = -1;
int const MAXN = 20000 + 5;
struct Q {
  int id;
  int t;
  bool start;
  Q(int id = 0, int t = 0, bool start = false) : id(id), t(t), start(start) {}
  friend bool operator<(Q const &a, Q const &b) {
    return a.t < b.t || a.t == b.t && a.start < b.start;
  }
};
int n, m, t;
int qs[MAXN];
Q bs[2 * MAXN];
int res[MAXN];
int idx[MAXN];
int sz;
int main() {
  scanf("%d %d %d\n", &n, &m, &t);
  for (int i = 0; i < int(n); ++i) {
    int hh, mm, ss;
    scanf("%d:%d:%d\n", &hh, &mm, &ss);
    int const p = ss + mm * 60 + hh * 60 * 60;
    qs[i] = p;
    bs[sz] = Q(i, p, true);
    ++sz;
    bs[sz] = Q(i, p + t, false);
    ++sz;
  }
  sort(bs, bs + sz);
  int id = 0;
  bool ok = false;
  map<int, int> cnt;
  for (int i = 0; i < int(sz); ++i) {
    Q &b = bs[i];
    if (!b.start) {
      auto const it(cnt.find(idx[b.id]));
      --(it->second);
      if (it->second == 0) cnt.erase(it);
    } else {
      if (cnt.size() < m) {
        res[b.id] = ++id;
        cnt.insert(make_pair(id, 1));
        idx[b.id] = id;
      } else {
        auto const it(--cnt.end());
        res[b.id] = it->first;
        ++(it->second);
        idx[b.id] = id;
      }
    }
    ok = ok || cnt.size() == m;
  }
  if (!ok) {
    cout << "No solution" << endl;
    return 0;
  }
  printf("%d\n", id);
  for (int i = 0; i < int(n); ++i) {
    printf("%d\n", res[i]);
  }
  return 0;
}
