#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
pair<int, int> a[20010];
int v[20010], sz[20010];
bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
int main() {
  int i, j, k, ca = 0, m, n, t;
  scanf("%d%d%d", &n, &m, &t);
  for (i = 0; i < n; i++) {
    int h, m, s;
    scanf("%d:%d:%d", &h, &m, &s);
    s = h * 3600 + m * 60 + s;
    a[i] = make_pair(s, s + t - 1);
  }
  sort(a, a + n);
  int id = 0, cnt = 0, ok = 0;
  for (i = 0, j = 0; i < n; i++) {
    int second = a[i].second;
    while (j < n && a[j].first <= second) {
      if (cnt >= m) {
        break;
      }
      if (!v[j]) v[j] = ++id, sz[id]++, cnt++;
      j++;
    }
    if (cnt >= m) {
      ok = 1;
      k = v[j - 1];
      while (j < n && a[j].first <= second) {
        if (!v[j]) v[j] = k, sz[k]++;
        j++;
      }
    }
    k = v[i];
    sz[k]--;
    if (sz[k] == 0) cnt--;
  }
  if (!ok)
    puts("No solution");
  else {
    printf("%d\n", id);
    for (i = 0; i < n; i++) printf("%d\n", v[i]);
  }
}
