#include <bits/stdc++.h>
using namespace std;
int dat[86500 * 5], cov[86500 * 5];
int ans[86500];
const int rt = 86400;
void build(int p, int l, int r) {
  dat[p] = cov[p] = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(p * 2, l, mid);
  build(p * 2 + 1, mid + 1, r);
}
void spread(int p) {
  if (cov[p]) {
    cov[p * 2] += cov[p];
    cov[p * 2 + 1] += cov[p];
    dat[p * 2] += cov[p];
    dat[p * 2 + 1] += cov[p];
    cov[p] = 0;
  }
}
void change(int p, int l, int r, int L, int R, int x) {
  if (L <= l && r <= R) {
    dat[p] += x;
    cov[p] += x;
    return;
  }
  spread(p);
  int mid = (l + r) >> 1;
  if (L <= mid) change(p * 2, l, mid, L, R, x);
  if (R > mid) change(p * 2 + 1, mid + 1, r, L, R, x);
  dat[p] = max(dat[p * 2], dat[p * 2 + 1]);
}
int ask(int p, int l, int r, int L, int R) {
  if (L <= l && r <= R) return dat[p];
  spread(p);
  int mid = (l + r) >> 1;
  if (L <= mid && R > mid)
    return max(ask(p * 2, l, mid, L, R), ask(p * 2 + 1, mid + 1, r, L, R));
  else if (L <= mid)
    return ask(p * 2, l, mid, L, R);
  else
    return ask(p * 2 + 1, mid + 1, r, L, R);
}
int main() {
  int n, m, T;
  scanf("%d%d%d", &n, &m, &T);
  build(1, 1, rt);
  int cnt = 0;
  int y;
  for (int i = 1; i <= n; i++) {
    int hh, mm, ss;
    scanf("%d:%d:%d", &hh, &mm, &ss);
    int x = hh * 60 * 60 + mm * 60 + ss;
    if (ask(1, 1, rt, x, x + T - 1) < m) {
      change(1, 1, rt, x, x + T - 1, 1);
      cnt++;
    } else {
      change(1, 1, rt, y, x + T - 1, 1);
    }
    y = x + T;
    ans[i] = cnt;
  }
  if (dat[1] == m) {
    cout << cnt << endl;
    for (int i = 1; i <= n; i++) {
      cout << ans[i] << endl;
    }
  } else
    cout << "No solution" << endl;
}
