#include <bits/stdc++.h>
using namespace std;
const int maxn = 200050;
int n, m, T, ans = 0, id[maxn];
bool z = 0;
pair<int, int> p[maxn];
int ps = 0;
int cnt[maxn];
int main() {
  int i, j, cur;
  scanf("%d%d%d", &n, &m, &T);
  for (i = 1; i <= n; i++) {
    int t1, t2, t3, tim;
    scanf("%d:%d:%d", &t1, &t2, &t3);
    tim = (t1 * 60 + t2) * 60 + t3;
    p[ps++] = make_pair(tim, i);
    p[ps++] = make_pair(tim + T, -i);
  }
  sort(p, p + ps);
  for (i = cur = 0; i < ps; i++) {
    if (p[i].second > 0) {
      if ((cur + 1) > m)
        cnt[id[p[i].second] = j]++;
      else
        cnt[j = id[p[i].second] = ++ans]++, cur++;
      if (cur >= m) z = 1;
    } else if (!--cnt[id[-p[i].second]])
      cur--;
  }
  if (!z)
    printf("No solution\n");
  else {
    printf("%d\n", ans);
    for (i = 1; i <= n; i++) printf("%d\n", id[i]);
  }
  return 0;
}
