#include <bits/stdc++.h>
using namespace std;
int n, m, t, a[20005], d[20005], c[20005], p;
bool ok;
int main() {
  scanf("%d %d %d", &n, &m, &t);
  for (int i = (0); i < (n); i++) {
    int x, y, z;
    scanf("%d:%d:%d", &x, &y, &z);
    a[i] = x * 3600 + y * 60 + z;
  }
  for (int i = (0); i < (n); i++) {
    d[i] = upper_bound(a, a + n, a[i] + t - 1) - a - 1;
    if (d[i] - i + 1 >= m) ok = 1;
  }
  if (!ok) {
    puts("No solution");
    return 0;
  }
  for (int i = (n - 1); i >= (0); i--) {
    if (d[i] == i)
      c[i] = ++p;
    else {
      if (p - c[d[i]] + 1 == m)
        c[i] = p;
      else
        c[i] = ++p;
    }
  }
  printf("%d\n", c[0]);
  for (int i = (0); i < (n); i++) printf("%d\n", c[i]);
  scanf("\n");
}
