#include <bits/stdc++.h>
using namespace std;
const int N = 101000;
int sum[N * 4], res[N], rn, last[N];
void updata(int rt, int l, int r, int x, int c) {
  if (l == r) {
    sum[rt] += c;
    return;
  }
  int m = (l + r) >> 1;
  if (x <= m)
    updata(rt << 1, l, m, x, c);
  else
    updata(rt << 1 | 1, m + 1, r, x, c);
  sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
}
int query(int rt, int l, int r, int tl, int tr) {
  if (tl <= l && r <= tr) return sum[rt];
  int m = (l + r) >> 1;
  if (tr <= m)
    return query(rt << 1, l, m, tl, tr);
  else if (m < tl)
    return query(rt << 1 | 1, m + 1, r, tl, tr);
  else
    return query(rt << 1, l, m, tl, m) +
           query(rt << 1 | 1, m + 1, r, m + 1, tr);
}
int main() {
  int n, m, t, h, mi, s, flag = 0;
  cin >> n >> m >> t;
  for (int i = 1; i <= n; i++) {
    scanf("%d:%d:%d", &h, &mi, &s);
    int time = h * 60 * 60 + mi * 60 + s + 1;
    int tmp = query(1, 1, 100000, max(1, time - t + 1), time);
    if (tmp < m) {
      res[i] = ++rn;
      last[rn] = time;
      updata(1, 1, 100000, time, 1);
    } else {
      res[i] = rn;
      updata(1, 1, 100000, time, 1);
      updata(1, 1, 100000, last[rn], -1);
      last[rn] = time;
    }
    if (tmp + 1 >= m) flag = 1;
  }
  if (!flag)
    cout << "No solution\n";
  else {
    cout << rn << endl;
    for (int i = 1; i <= n; i++) {
      printf("%d\n", res[i]);
    }
  }
}
