#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5;
vector<pair<int, pair<int, int> > > Ev;
vector<int> V;
int Id[MAX], Cnt[MAX];
int main() {
  int N, M, T;
  scanf("%d%d%d", &N, &M, &T);
  for (int i = 0; i < (N); ++i) {
    int h, m, s;
    scanf("%d:%d:%d", &h, &m, &s);
    int z = (h * 60 + m) * 60 + s;
    Ev.push_back(make_pair(z, make_pair(1, i))),
        Ev.push_back(make_pair(z + T, make_pair(-1, i)));
  }
  sort((Ev).begin(), (Ev).end());
  int z = 1, bal = 0;
  bool ok = 0;
  for (int i = 0; i < (int)Ev.size(); ++i) {
    int q = Ev[i].second.second;
    if (Ev[i].second.first == 1) {
      if (bal < M)
        V.push_back(z++), Id[q] = z - 1, ++Cnt[z - 1];
      else
        V.push_back(z - 1), Id[q] = z - 1, ok = 1, ++Cnt[z - 1];
      if (Cnt[z - 1] == 1) ++bal;
      if (bal == M) ok = 1;
    } else if ((--Cnt[Id[q]]) == 0)
      --bal;
  }
  if (!ok)
    puts("No solution");
  else {
    printf("%d\n", z - 1);
    for (__typeof((V).begin()) i = (V).begin(); i != (V).end(); ++i)
      printf("%d\n", *i);
  }
  return 0;
}
