#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 * 100 + 10;
int endss[maxn];
int main() {
  int n, M, T;
  cin >> n >> M >> T;
  vector<pair<pair<int, int>, int> > ps(2 * n);
  for (int i = 0; i < n; i++) {
    int h, m, s;
    scanf("%d:%d:%d\n", &h, &m, &s);
    int time = 60 * (60 * h + m) + s;
    ps[2 * i] = make_pair(make_pair(time, 0), i);
    ps[2 * i + 1] = make_pair(make_pair(time + T - 1, 1), i);
  }
  sort(ps.begin(), ps.end());
  int cur = -1;
  int online = 0;
  vector<int> ans(n);
  bool ok = false;
  for (int i = 0; i < (int)(ps).size(); i++) {
    if (ps[i].first.second == 0) {
      online++;
      if (online > M) {
        online--;
      } else {
        if (online == M) ok = true;
        cur++;
      }
      ans[ps[i].second] = cur;
      endss[cur]++;
    } else {
      if (endss[ans[ps[i].second]]) endss[ans[ps[i].second]]--;
      if (!endss[ans[ps[i].second]]) online--;
    }
  }
  if (!ok)
    puts("No solution");
  else {
    printf("%d\n", cur + 1);
    for (int i = 0; i < n; i++) printf("%d\n", ans[i] + 1);
  }
  return 0;
}
