#include <bits/stdc++.h>
using namespace std;
int a[20001] = {0};
multiset<int> s;
vector<int> v;
int main() {
  int i, j, fl, t, k, l, n, m, r, x, y, z;
  cin >> n >> m >> t;
  char c;
  for (i = 1; i <= n; i++) {
    cin >> x >> c >> y >> c >> z;
    a[i] = x * 3600 + y * 60 + z;
  }
  k = 0;
  int kol = 0;
  set<int>::iterator ii;
  fl = 0;
  int last = 0;
  for (i = 1; i <= n; i++) {
    while (s.size() > 0 && (*s.begin()) <= a[i]) {
      s.erase(s.begin());
      k--;
    }
    if (k == m) {
      v.push_back(last);
      fl = 1;
      ii = s.end();
      ii--;
      s.erase(ii);
      s.insert(a[i] + t);
    } else {
      kol++;
      last = kol;
      v.push_back(last);
      k++;
      s.insert(a[i] + t);
    }
  }
  if (k == m) fl = 1;
  if (!fl) {
    cout << "No solution" << endl;
    return 0;
  }
  cout << kol << endl;
  for (i = 0; i < v.size(); i++) cout << v[i] << endl;
  getchar();
  getchar();
  return 0;
}
