#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, t;
  cin >> n >> m >> t;
  multiset<pair<int, int> > alive;
  int maxId = 0;
  vector<int> res(n);
  bool flag = false;
  for (int i = 0; i < n; ++i) {
    int hour, minute, sec;
    scanf("%d%*c%d%*c%d", &hour, &minute, &sec);
    int time = hour * 60 * 60 + minute * 60 + sec;
    while (alive.size() > 0 && (alive.begin()->first) <= time)
      alive.erase(alive.begin());
    if (alive.size() == m) {
      res[i] = alive.rbegin()->second;
      auto t1 = alive.rbegin();
      auto t2 = alive.find(*t1);
      alive.erase(t2);
      alive.insert(make_pair(time + t, res[i]));
    } else {
      res[i] = ++maxId;
      alive.insert(make_pair(time + t, res[i]));
      if (alive.size() == m) flag = true;
    }
  }
  if (!flag) {
    cout << "No solution" << endl;
    return 0;
  }
  cout << maxId << endl;
  for (int i = 0; i < n; ++i) printf("%d\n", res[i]);
  return 0;
}
