#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
vector<int> open[MAX];
int ans[MAX];
set<pair<int, int> > s;
int main() {
  int n, m, t;
  scanf("%d %d %d", &n, &m, &t);
  for (int i = 0; i < n; i++) {
    int h, m, s;
    scanf("%d:%d:%d", &h, &m, &s);
    open[h * 3600 + m * 60 + s].push_back(i);
  }
  int res = 0;
  bool flag = false;
  for (int i = 0; i < MAX; i++) {
    while (!s.empty() && s.begin()->first + t == i) s.erase(s.begin());
    for (int j = 0; j < open[i].size(); j++) {
      int id = open[i][j];
      if (s.size() == m - 1) flag = true;
      if (s.size() == m) {
        pair<int, int> p = *s.rbegin();
        s.erase(p);
        p.first = i;
        ans[id] = p.second;
        s.insert(p);
      } else {
        ans[id] = ++res;
        s.insert(make_pair(i, res));
      }
    }
  }
  if (!flag)
    printf("No solution\n");
  else {
    printf("%d\n", res);
    for (int i = 0; i < n; i++) printf("%d\n", ans[i]);
  }
  return 0;
}
