#include <bits/stdc++.h>
using namespace std;
const int N = 20005;
int t[N], ans[N];
int que[N];
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);
    t[i] = s + m * 60 + h * 3600;
  }
  int fr = 0, re = 0, reach = 0, label = 0;
  for (int i = 0; i < n; ++i) {
    while (fr != re && que[fr] + T - 1 < t[i]) ++fr;
    int now = re - fr;
    if (now + 1 <= M) {
      ans[i] = ++label;
      que[re++] = t[i];
    } else {
      ans[i] = label;
      que[re - 1] = t[i];
    }
    reach |= (re - fr == M);
  }
  if (!reach)
    puts("No solution");
  else {
    printf("%d\n", label);
    for (int i = 0; i < n; ++i) printf("%d\n", ans[i]);
  }
  return 0;
}
