#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 22222;
int N, M, T;
int ans[MAX_N];
set<pair<int, int> > S;
int main() {
  int h, m, s;
  int reached = 0;
  int nunique = 0;
  scanf("%d%d%d", &N, &M, &T);
  for (int i = 0; i < N; i++) {
    scanf("%d:%d:%d", &h, &m, &s);
    s += m * 60 + h * 60 * 60;
    while (!S.empty() && S.begin()->first + T - 1 < s) S.erase(S.begin());
    if (((int)(S).size()) == M) {
      auto it = S.end();
      it--;
      ans[i] = it->second;
      S.erase(it);
    } else {
      ans[i] = nunique++;
    }
    S.insert(make_pair(s, ans[i]));
    if (((int)(S).size()) == M) {
      reached = 1;
    }
  }
  if (!reached) {
    puts("No solution");
  } else {
    printf("%d\n", nunique);
    for (int i = 0; i < N; i++) printf("%d\n", ans[i] + 1);
  }
  return 0;
}
