#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500000;
int n, M, T, lastId;
int id[MAXN];
map<int, int> ids;
set<pair<int, int> > dp;
void EraseFirst() {
  int u = dp.begin()->second;
  dp.erase(dp.begin());
  --ids[id[u]];
  if (!ids[id[u]]) {
    ids.erase(id[u]);
  }
}
int main() {
  cin >> n >> M >> T;
  char wasM = 0;
  for (int i = 0; i < n; ++i) {
    int hh, mm, ss;
    scanf("%d:%d:%d", &hh, &mm, &ss);
    int t = ss + mm * 60 + hh * 3600;
    for (; (int((dp).size())) && dp.begin()->first <= t - T;) {
      EraseFirst();
    }
    if ((int((ids).size())) < M) {
      id[i] = lastId++;
    } else {
      wasM = 1;
      id[i] = id[dp.rbegin()->second];
    }
    ++ids[id[i]];
    dp.insert(make_pair(t, i));
  }
  if (!wasM && (int((ids).size())) < M) {
    puts("No solution");
  } else {
    printf("%d\n", lastId);
    for (int i = 0; i < n; ++i) {
      printf("%d\n", id[i] + 1);
    }
  }
  return 0;
}
