#include <bits/stdc++.h>
using namespace std;
const int N = 20005;
int t[N];
int ans[N];
multiset<int> use, nouse;
int c[N];
int kind = 0;
int main() {
  int n, M, T;
  scanf("%d%d%d", &n, &M, &T);
  for (int i = (1); i <= (int)n; i++) {
    int h, m, s;
    scanf("%d:%d:%d", &h, &m, &s);
    t[i] = h * 3600 + m * 60 + s;
  }
  int R = 0;
  int l = 1;
  bool arrive = 0;
  for (int i = (1); i <= (int)n; i++) {
    while (t[l] + T - 1 < t[i]) {
      use.erase(use.find(ans[l]));
      c[ans[l]]--;
      if (c[ans[l]] == 0) kind--;
      l++;
    }
    if (kind == M) {
      if (!use.size()) return 0;
      arrive = 1;
      ans[i] = *(--use.end());
      c[ans[i]]++;
      use.insert(ans[i]);
    } else {
      ans[i] = ++R;
      use.insert(ans[i]);
      c[ans[i]]++;
      kind++;
    }
  }
  if (kind == M) arrive = 1;
  if (!arrive) {
    printf("No solution\n");
  } else {
    printf("%d\n", R);
    for (int i = (1); i <= (int)n; i++) printf("%d\n", ans[i]);
  }
}
