#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m, t;
  cin >> n >> m >> t;
  vector<int> v(n);
  vector<int> ans(n);
  set<int> w;
  for (int i = 0; i < n; ++i) {
    int hh, mm, ss;
    char ch;
    cin >> hh >> ch >> mm >> ch >> ss;
    int q = hh * 3600 + mm * 60 + ss;
    v[i] = q;
  }
  map<int, int> mx_;
  std::set<pair<int, int> > mx;
  int id = 0;
  int mmmax = 0;
  for (int i = 0; i < n; ++i) {
    int x = w.size();
    if (x < m)
      ans[i] = ++id;
    else
      ans[i] = *w.rbegin();
    w.insert(ans[i]);
    mmmax = std::max(mmmax, (int)w.size());
    if (mx.count({mx_[ans[i]], ans[i]})) {
      mx.erase({mx_[ans[i]], ans[i]});
    }
    mx.insert({v[i] + t, ans[i]});
    mx_[ans[i]] = v[i] + t;
    if (i + 1 < n) {
      for (auto& pr : mx) {
        if (pr.first <= v[i + 1]) {
          w.erase(pr.second);
        } else {
          break;
        }
      }
    }
  }
  set<int> ww;
  for (int i = 0; i < n; ++i) {
    ww.insert(ans[i]);
  }
  if (mmmax < m) {
    cout << "No solution" << endl;
    return 0;
  }
  cout << ww.size() << endl;
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << endl;
  }
}
