#include <bits/stdc++.h>
using namespace std;
int n, M, L, T, A, B, C, i, h, flag, now, t, ans[50005], q[50005];
int main() {
  scanf("%d%d%d", &n, &M, &L);
  ans[0] = 0;
  h = 1;
  t = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d:%d:%d", &A, &B, &C);
    T = A * 3600 + B * 60 + C;
    while (h <= t && q[h] < T) h++;
    if (t - h + 1 < M)
      q[++t] = T + L - 1, ans[i] = ++now;
    else
      q[t] = T + L - 1, ans[i] = now;
    if (t - h + 1 == M) flag = 1;
    if (now > *ans) *ans = now;
  }
  if (flag ^ 1)
    puts("No solution");
  else
    for (i = 0; i <= n; i++) printf("%d\n", ans[i]);
}
