#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, M, t;
  scanf("%d %d %d", &n, &M, &t);
  int currently = 0;
  vector<pair<int, int> > ans;
  int max_n = 0;
  bool zbs = false;
  for (int i = 0; i < n; i++) {
    int h, m, s;
    scanf("%d:%d:%d", &h, &m, &s);
    int ts = 3600 * h + 60 * m + s;
    currently = 0;
    bool wasColor[20001] = {false};
    for (int j = 0; j < i; j++)
      if ((ans[j].first + t - 1 >= ts) && (wasColor[ans[j].second] == false)) {
        currently++;
        wasColor[ans[j].second] = true;
      }
    if (currently == M) {
      ans.push_back(make_pair(ts, max_n));
      zbs = true;
    } else {
      ans.push_back(make_pair(ts, ++max_n));
      if (++currently == M) zbs = true;
    }
  }
  if (!zbs) return cout << "No solution", 0;
  cout << max_n << "\n";
  for (int i = 0; i < ans.size(); i++) cout << ans[i].second << "\n";
}
