#include <bits/stdc++.h>
using namespace std;
int foo(char x) { return x - '0'; }
int foo(char x, char y) { return foo(x) * 10 + foo(y); }
int TimeToSec(string s) {
  return foo(s[0], s[1]) * 60 * 60 + foo(s[3], s[4]) * 60 + foo(s[6], s[7]);
}
const int maxT = 86400;
const int maxn = 20200;
int add[maxT * 5], maxi[maxT * 5];
int n, M, T, R;
int id[maxn];
int getMax(int v, int tl, int tr, int l, int r) {
  if (tl == l && tr == r) {
    return add[v] + maxi[v];
  }
  int tm = (tl + tr) >> 1;
  if (r <= tm)
    return getMax((v << 1) + 1, tl, tm, l, r) + add[v];
  else if (l > tm)
    return getMax((v << 1) + 2, tm + 1, tr, l, r) + add[v];
  else {
    return max(getMax((v << 1) + 1, tl, tm, l, tm),
               getMax((v << 1) + 2, tm + 1, tr, tm + 1, r)) +
           add[v];
  }
}
void upd(int v) {
  int l = (v << 1) + 1;
  int r = (v << 1) + 2;
  if (add[l] + maxi[l] > add[r] + maxi[r]) {
    maxi[v] = add[l] + maxi[l];
  } else {
    maxi[v] = add[r] + maxi[r];
  }
}
void addT(int v, int tl, int tr, int l, int r, int val) {
  if (tl == l && tr == r) {
    add[v] += val;
    return;
  }
  int tm = (tl + tr) >> 1;
  if (r <= tm)
    addT((v << 1) + 1, tl, tm, l, r, val);
  else if (l > tm)
    addT((v << 1) + 2, tm + 1, tr, l, r, val);
  else {
    addT((v << 1) + 1, tl, tm, l, tm, val);
    addT((v << 1) + 2, tm + 1, tr, tm + 1, r, val);
  }
  upd(v);
}
int main() {
  srand(time(0));
  cin >> n >> M >> T;
  int maximalR = -1;
  int maximalRId = 1;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    int l = TimeToSec(s);
    int r = l + T - 1;
    if (getMax(0, 0, maxT, l, r) < M) {
      id[i] = ++R;
      addT(0, 0, maxT, l, r, 1);
      maximalR = r;
      maximalRId = id[i];
    } else {
      id[i] = maximalRId;
      if (maximalR + 1 > r) continue;
      addT(0, 0, maxT, maximalR + 1, r, 1);
      maximalR = r;
      maximalRId = id[i];
    }
  }
  if (getMax(0, 0, maxT, 0, maxT) != M) {
    cout << "No solution\n";
    exit(0);
  }
  cout << R << "\n";
  for (int i = 1; i <= n; i++) cout << id[i] << "\n";
  return 0;
}
