#include <bits/stdc++.h>
using namespace std;
const int nmax = 20005;
int n, m, t, a, b, c, i, x, y, z, cnt, ok, sol[nmax];
set<pair<int, int> > s;
set<pair<int, int> >::iterator it;
int main() {
  scanf("%d%d%d", &n, &m, &t);
  ok = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d:%d:%d\n", &a, &b, &c);
    x = a * 3600 + b * 60 + c;
    y = x + t - 1;
    while (!s.empty()) {
      it = s.begin();
      if (it->first < x)
        s.erase(it);
      else
        break;
    }
    if (s.size() == m) {
      it = s.end();
      it--;
      sol[i] = sol[it->second];
      s.erase(it);
    } else
      sol[i] = ++cnt;
    s.insert(make_pair(y, i));
    if (s.size() == m) ok = 1;
  }
  if (!ok) {
    printf("No solution\n");
    return 0;
  }
  printf("%d\n", cnt);
  for (i = 1; i <= n; i++) printf("%d\n", sol[i]);
  return 0;
}
