#include <bits/stdc++.h>
using namespace std;
bool flag = 0;
int R[100005];
priority_queue<pair<int, int> > Q;
char st[100005];
int ans = 0, c[100005];
int n, m, len = 0, T, cnt, col[100005];
struct ran {
  int num, l, s;
} A[100005];
bool cmp(ran p, ran q) { return p.l < q.l || (p.l == q.l && p.s < q.s); }
void read(int t) {
  int h, m, s, ti;
  scanf("%s", st + 1);
  h = (st[1] - '0') * 10 + st[2] - '0';
  m = (st[4] - '0') * 10 + st[5] - '0';
  s = (st[7] - '0') * 10 + st[8] - '0';
  ti = h * 3600 + m * 60 + s;
  A[++len] = (ran){t, ti, 1};
  A[++len] = (ran){t, ti + T, -1};
  R[t] = ti + T - 1;
}
int main() {
  int i;
  pair<int, int> x;
  scanf("%d %d %d\n", &n, &m, &T);
  for (i = 1; i <= n; i++) read(i);
  sort(A + 1, A + len + 1, cmp);
  for (i = 1; i <= len; i++)
    if (A[i].s < 0) {
      c[col[A[i].num]]--;
      if (!c[col[A[i].num]]) cnt--;
    } else {
      if ((++cnt) >= m) flag = 1;
      if (cnt <= m)
        col[A[i].num] = ++ans;
      else {
        x = Q.top(), cnt--;
        col[A[i].num] = col[x.second];
      }
      c[col[A[i].num]]++;
      Q.push(pair<int, int>(R[A[i].num], A[i].num));
    }
  if (!flag)
    printf("No solution");
  else {
    printf("%d\n", ans);
    for (i = 1; i <= n; i++) printf("%d\n", col[i]);
  }
  return 0;
}
