#include <bits/stdc++.h>
using namespace std;
int n, m, t, a[20010], maxim, id[20010], s, e, ans[20010], ansN;
pair<int, int> q[20010];
bool byA(int x, int y) { return a[x] < a[y]; }
int main() {
  int x, y, z;
  scanf("%d %d %d\n", &n, &m, &t);
  for (int i = 0; i < n; i++) {
    scanf("%d:%d:%d\n", &x, &y, &z);
    id[i] = i;
    a[i] = x * 3600 + y * 60 + z;
  }
  sort(id, id + n, byA);
  int online = 0;
  for (int i = 0; i < n; i++) {
    int x = a[id[i]];
    while (e - s && q[s].first + t - 1 < x) s++;
    if (e - s)
      online = ans[q[e - 1].second] - ans[q[s].second] + 1;
    else
      online = 0;
    if (online == m)
      ans[id[i]] = ansN;
    else
      ans[id[i]] = ++ansN, online++;
    maxim = max(maxim, online);
    q[e++] = pair<int, int>(x, id[i]);
  }
  if (maxim != m)
    printf("No solution");
  else {
    printf("%d\n", ansN);
    for (int i = 0; i < n; i++) printf("%d\n", ans[i]);
  }
}
