#include <bits/stdc++.h>
using namespace std;
const int N = 101010;
bool reach;
int n, m, t, cnt, l, r;
int a[N], ans[N], que[N];
int main() {
  scanf("%d%d%d", &n, &m, &t);
  for (int i = (1); i < (n + 1); i++) {
    int x, y, z;
    scanf("%d:%d:%d", &x, &y, &z);
    a[i] = x * 3600 + y * 60 + z;
  }
  l = 1, r = 0;
  for (int i = (1); i < (n + 1); i++) {
    while (l <= r && a[que[l]] < a[i] - t + 1) ++l;
    if (r - l + 1 < m) {
      ans[i] = ++cnt;
      que[++r] = i;
    } else {
      ans[i] = cnt;
      que[r] = i;
    }
    if (r - l + 1 >= m) reach = 1;
  }
  if (reach) {
    printf("%d\n", cnt);
    for (int i = (1); i < (n + 1); i++) printf("%d\n", ans[i]);
  } else {
    puts("No solution");
  }
  return 0;
}
