#include <bits/stdc++.h>
using namespace std;
int a[86405];
int n, m, t;
int Q[86405];
int ans[86405];
int main() {
  bool flag;
  int l, r;
  int H, M, S;
  int num;
  while (scanf("%d%d%d", &n, &m, &t) != EOF) {
    num = 0;
    flag = false;
    l = r = 0;
    memset(Q, 0, sizeof(Q));
    for (int i = 0; i < n; i++) {
      scanf("%d:%d:%d", &H, &M, &S);
      a[i] = S + M * 60 + H * 3600;
      Q[r++] = i;
      while (l < r && a[Q[r - 1]] - a[Q[l]] >= t) l++;
      if (r - l == m) flag = true;
      if (r - l <= m)
        ans[i] = ++num;
      else {
        ans[i] = ans[Q[r - 2]];
        Q[r - 2] = Q[r - 1];
        r--;
      }
    }
    if (flag) {
      printf("%d\n", num);
      for (int i = 0; i < n; i++) printf("%d\n", ans[i]);
    } else
      puts("No solution");
  }
  return 0;
}
