#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, T;
  scanf("%d %d %d", &N, &M, &T);
  vector<int> I(N);
  for (int i = 0; i < N; i++) {
    int d, m, s;
    scanf("%d:%d:%d", &d, &m, &s);
    I[i] = d * 60 * 60 + m * 60 + s;
  }
  int a = 0, b = 0, mm = 0;
  set<pair<int, int> > S;
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    while (!S.empty() && S.begin()->first + T <= I[i]) {
      S.erase(S.begin());
      a--;
    }
    if (a == M) {
      ans[i] = S.rbegin()->second;
      S.erase(--S.end());
    } else {
      ans[i] = ++b;
      a++;
    }
    S.insert(make_pair(I[i], ans[i]));
    mm = max(mm, a);
  }
  if (mm < M) {
    cout << "No solution\n";
    return 0;
  }
  cout << b << "\n";
  for (int i = 0; i < N; i++) cout << ans[i] << "\n";
  return 0;
}
