#include <bits/stdc++.h>
using namespace std;
int n, m, t, i, j, a[20005], c, b[20005], answ, flag, out[20005], z, ans[20005],
    k, h, ina, inb;
string s;
int main() {
  scanf("%d%d%d", &n, &m, &t);
  for (i = 1; i <= n; i++) {
    cin >> s;
    c = (s[0] - '0') * 10 + s[1] - '0';
    a[i] += c * 3600;
    c = (s[3] - '0') * 10 + s[4] - '0';
    a[i] += c * 60;
    c = (s[6] - '0') * 10 + s[7] - '0';
    a[i] += c;
    b[i] = a[i] + t - 1;
  }
  for (i = 1; i <= n; i++) {
    ina = i + 1;
    inb = n;
    answ = i;
    while (ina <= inb) {
      int m = (ina + inb) / 2;
      if (a[m] <= b[i]) {
        ina = m + 1;
        answ = m;
      } else
        inb = m - 1;
    }
    out[i] = answ;
    if (answ - i + 1 >= m) flag = 1;
  }
  if (flag == 0)
    printf("No solution\n");
  else {
    i = 1;
    h = 0;
    while (i != n + 1) {
      for (j = max(i, h); j <= out[i]; j++) {
        if (k < m) {
          ans[j] = ++z;
          k++;
        } else
          ans[j] = z;
      }
      h = out[i] + 1;
      i++;
      if (ans[i] == ans[i - 1])
        k = k;
      else
        k--;
    }
    printf("%d\n", z);
    for (i = 1; i <= n; i++) printf("%d\n", ans[i]);
  }
  return 0;
}
