#include <bits/stdc++.h>
using namespace std;
int n, m, t;
struct node {
  int l, r;
} a[20050];
int cnt[90000], ans[20050];
bool cmp(const node &a, const node &b) { return a.l < b.l; }
int main() {
  scanf("%d%d%d", &n, &m, &t);
  int x, y, z;
  for (int i = (1); i <= (n); i++) {
    scanf("%d:%d:%d", &x, &y, &z);
    int _ = x * 3600 + y * 60 + z;
    a[i] = (node){_, _ + t};
    cnt[_]++;
    cnt[_ + t]--;
  }
  int sum = 0, nos = 1;
  for (int i = (0); i <= (86400); i++) {
    sum += cnt[i];
    if (sum >= m) nos = 0;
    cnt[i] = 0;
  }
  if (nos) {
    cout << "No solution" << endl;
    return 0;
  }
  sort(a + 1, a + n + 1, cmp);
  for (int i = (1); i <= (n); i++) cnt[a[i].r]--;
  sum = 0;
  int num = 0, j = 0, la = 0;
  for (int i = (0); i <= (86400); i++) {
    sum += cnt[i];
    while (j + 1 <= n && a[j + 1].l == i) {
      j++;
      if (sum < m) {
        sum++;
        ans[la = j] = ++num;
      } else {
        cnt[a[la].r]++;
        ans[la = j] = num;
      }
    }
  }
  cout << num << endl;
  for (int i = (1); i <= (n); i++) printf("%d\n", ans[i]);
  return 0;
}
