#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int MAXN = 2.1e4;
int main() {
  int n, mx, T;
  cin >> n >> mx >> T;
  static int t[MAXN];
  for (int i = 0; i < int(n); ++i) {
    int h, m, s;
    scanf("%d:%d:%d", &h, &m, &s);
    t[i] = 60 * (60 * h + m) + s;
  }
  multiset<int> q;
  int I = 0;
  int res[MAXN];
  bool solved = 0;
  for (int i = 0; i < int(n); ++i) {
    while (q.size() && t[i] - *q.begin() >= T) {
      q.erase(q.begin());
    }
    if (int(q.size()) < mx) {
      res[i] = ++I;
      q.insert(t[i]);
      if (int(q.size()) == mx) {
        solved = 1;
      }
    } else {
      res[i] = res[i - 1];
      q.erase(q.find(t[i - 1]));
      q.insert(t[i]);
    }
  }
  if (!solved) {
    cout << "No solution";
    return 0;
  }
  printf("%d\n", I);
  for (int i = 0; i < int(n); ++i) {
    printf("%d\n", res[i]);
  }
}
