#include <bits/stdc++.h>
using namespace std;
int n, m, t;
int ans[30000];
vector<pair<int, int> > vv;
pair<int, int> tmp[30010];
int gl = 1;
int main() {
  cin >> n >> m >> t;
  for (int i = 1; i <= n; i++) {
    int a, b, c;
    scanf("%d:%d:%d", &a, &b, &c);
    int sec = (a * 60 + b) * 60 + c;
    vv.push_back(make_pair(sec, i));
    vv.push_back(make_pair(sec + t, -i));
  }
  sort(vv.begin(), vv.end());
  set<pair<int, int> > ss;
  bool ki = 0;
  for (auto elem : vv) {
    if (elem.second < 0)
      ss.erase(make_pair(-elem.first, -elem.second));
    else {
      ss.insert(make_pair(-(elem.first + t), elem.second));
      ki |= (ss.size() >= m);
      if (ss.size() > m) {
        int sz = 0;
        int par = 0;
        for (auto pr : ss) {
          tmp[sz] = pr;
          if (ans[pr.second]) {
            if (par != 0 && par != ans[pr.second]) assert(0);
            par = ans[pr.second];
          }
          sz++;
          if (sz > ss.size() - m) break;
        }
        if (par == 0) par = gl++;
        for (int i = 0; i < sz; i++) ans[tmp[i].second] = par;
        for (int i = 1; i < sz; i++) ss.erase(tmp[i]);
      }
    }
  }
  for (int i = 1; i <= n; i++)
    if (!ans[i]) ans[i] = gl++;
  if (!ki)
    cout << "No solution";
  else {
    cout << (gl - 1) << endl;
    for (int i = 1; i <= n; i++) cout << ans[i] << endl;
  }
  return 0;
}
