#include <bits/stdc++.h>
using namespace std;
int main(void) {
  multiset<int> req;
  vector<int> ans;
  int n, m, T;
  int id = 0;
  bool t = false;
  cin >> n >> m >> T;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < (int)s.length(); j++) s[j] -= '0';
    int time = ((s[0]) * 10 + (s[1])) * 3600 + ((s[3]) * 10 + s[4]) * 60 +
               (s[6] * 10 + s[7]);
    while (((int)req.size() > 0) && (*req.begin() < time))
      req.erase(req.begin());
    if ((int)req.size() < m) {
      ++id;
    } else {
      set<int>::iterator it;
      it = req.find(*req.rbegin());
      req.erase(it);
    }
    ans.push_back(id);
    req.insert(time + T - 1);
    if ((int)req.size() == m) t = true;
  }
  if (!t)
    cout << "No solution";
  else {
    cout << id << endl;
    for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] << endl;
  }
  return 0;
}
