#include <bits/stdc++.h>
using namespace std;
int hh, mm, ss, n, T, M;
int get() { return hh * 60 * 60 + mm * 60 + ss; }
int main() {
  cin >> n >> M >> T;
  deque<pair<int, int> > dq;
  int c = 0;
  bool r = 0;
  vector<int> out;
  for (int i = 0; i < n; ++i) {
    scanf("%d:%d:%d", &hh, &mm, &ss);
    int s = get();
    while (dq.size() && dq.front().first < s) dq.pop_front();
    if (dq.size() < M) {
      dq.push_back(pair<int, int>(s + T - 1, c));
      out.push_back(c++);
    } else {
      dq.back().first = s + T - 1;
      out.push_back(dq.back().second);
    }
    if (dq.size() == M) r = 1;
  }
  if (!r) return puts("No solution");
  cout << c << endl;
  for (int i = 0; i < n; ++i) cout << out[i] + 1 << endl;
}
