#include <bits/stdc++.h>
using namespace std;
const int MAXN = 86400 * 2 + 100;
int n, m, k, p, q, maxn, ans[MAXN], d[MAXN], a[MAXN];
bool flag = false;
void rd(int i) {
  char st[11];
  scanf("%s", st);
  a[i] = ((st[0] - '0') * 10 + (st[1] - '0')) * 3600 +
         ((st[3] - '0') * 10 + (st[4] - '0')) * 60 +
         ((st[6] - '0') * 10 + (st[7] - '0'));
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++) rd(i);
  int num = 0;
  for (int i = 1; i <= n; i++) {
    if (p < q && d[p] < a[i]) p++;
    if (q - p == m) {
      d[q - 1] = a[i] + k - 1;
      ans[i] = num;
    } else {
      d[q++] = a[i] + k - 1;
      ans[i] = ++num;
    }
    maxn = max(maxn, q - p);
  }
  if (maxn != m)
    printf("No solution\n");
  else {
    printf("%d\n", num);
    for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);
  }
}
