#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, T, t, F;
int a[20010], an[20010], g[20010];
inline int read() {
  char p[20];
  scanf("%s", p + 1);
  int A = (p[1] - '0') * 10 + (p[2] - '0');
  int B = (p[4] - '0') * 10 + (p[5] - '0');
  int C = (p[7] - '0') * 10 + (p[8] - '0');
  return C + B * 60 + A * 3600;
}
inline bool cc1(const int &A, const int &B) { return a[A] < a[B]; }
int main() {
  scanf("%d%d%d", &n, &m, &T);
  for (i = 1; i <= n; i++) a[i] = read();
  int l, r;
  l = 1, r = 0;
  for (i = 1; i <= n; i++) {
    int A = i;
    for (; l <= r && a[g[l]] + T <= a[A]; l++)
      ;
    int cen = r - l + 1;
    if (cen == m)
      an[A] = an[g[r]], F = 1, g[r] = A;
    else {
      an[A] = ++t;
      g[++r] = A;
      if (cen + 1 == m) F = 1;
    }
  }
  if (!F)
    printf("No solution\n");
  else {
    printf("%d\n", t);
    for (i = 1; i <= n; i++) printf("%d\n", an[i]);
  }
  return 0;
}
