#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
int ans[MAXN];
int main() {
  int n, M, T;
  scanf("%d%d%d", &n, &M, &T);
  vector<int> pts;
  for (int i = 0; i < n; i++) {
    int h, m, s, r;
    scanf("%2d:%2d:%2d", &h, &m, &s);
    r = h * 60 * 60 + m * 60 + s;
    pts.push_back(r);
  }
  sort(pts.begin(), pts.end());
  deque<pair<int, int>> cur;
  int r = 0;
  bool mx_reached = false;
  for (int i = 0; i < n; i++) {
    while (!cur.empty() && cur.front().first + T <= pts[i]) {
      cur.pop_front();
    }
    if (cur.size() < M) {
      ans[i] = ++r;
      cur.push_back(make_pair(pts[i], r));
      if (cur.size() == M) mx_reached = true;
    } else {
      auto item = cur.back();
      cur.pop_back();
      item.first = pts[i];
      cur.push_back(item);
      ans[i] = item.second;
    }
  }
  if (!mx_reached) {
    printf("No solution");
  } else {
    printf("%d\n", r);
    for (int i = 0; i < n; i++) {
      printf("%d\n", ans[i]);
    }
  }
}
