#include <bits/stdc++.h>
using namespace std;
const int N = 22222;
int n, m, t, x, y, z, p = 0, id = 0, cnt = 0, a[N], b[N];
char s[22];
bool ok = false;
int main() {
  scanf("%d %d %d", &n, &m, &t);
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    for (int j = 0; s[j] != '\0'; j++) {
      if (s[j] == ':') {
        s[j] = ' ';
      }
    }
    stringstream ss(s);
    ss >> x >> y >> z;
    a[i] = x * 3600 + y * 60 + z;
  }
  for (int i = 0; i < n; i++) {
    while (a[p] + t <= a[i]) {
      if (b[p] != b[p + 1]) {
        --cnt;
      }
      ++p;
    }
    if (cnt == m) {
      b[i] = b[i - 1];
    } else {
      b[i] = ++id;
      ++cnt;
    }
    ok |= cnt == m;
  }
  if (!ok) {
    puts("No solution");
    exit(0);
  }
  printf("%d\n", id);
  for (int i = 0; i < n; i++) {
    printf("%d\n", b[i]);
  }
  return 0;
}
