#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, M, T;
  bool flag = false;
  int a, b, c, ans = 0, cnt = 0;
  int id[20005], idi = 0;
  scanf("%d %d %d", &n, &M, &T);
  queue<int> my_queue;
  while (n--) {
    scanf("%d:%d:%d", &a, &b, &c);
    int t = a * 3600 + b * 60 + c;
    while (!my_queue.empty() && my_queue.front() < t) my_queue.pop();
    if (my_queue.size() == M) {
      my_queue.back() = t + T - 1;
      id[idi++] = cnt;
    } else {
      ans++;
      my_queue.push(t + T - 1);
      id[idi++] = ++cnt;
    }
    if (my_queue.size() == M) flag = true;
  }
  if (flag) {
    printf("%d\n", ans);
    for (int i = 0; i < idi; i++) printf("%d\n", id[i]);
  } else
    printf("No solution\n");
}
