#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int n, maxhave, T;
int t[20000];
int q[20000], qhead, qtail;
int ret[20000];
void run() {
  scanf("%d%d%d", &n, &maxhave, &T);
  for (int i = (0); i < (n); ++i) {
    int a, b, c;
    scanf("%d:%d:%d", &a, &b, &c);
    t[i] = a * 3600 + b * 60 + c;
  }
  qhead = qtail = 0;
  bool ok = false;
  for (int i = (0); i < (n); ++i) {
    while (qtail < qhead && q[qtail] < t[i]) ++qtail;
    if (qhead - qtail == maxhave)
      q[qhead - 1] = t[i] + T - 1;
    else
      q[qhead++] = t[i] + T - 1;
    if (qhead - qtail == maxhave) ok = true;
    ret[i] = qhead;
  }
  if (!ok)
    printf("No solution\n");
  else {
    printf("%d\n", qhead);
    for (int i = (0); i < (n); ++i) printf("%d\n", ret[i]);
  }
}
int main() {
  run();
  return 0;
}
