#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
int n, m, t;
int app[MAX], ans[MAX];
int main() {
  scanf("%d %d %d%*c", &n, &m, &t);
  vector<tuple<int, int, int> > events;
  for (int i = int(0); i < int(n); i++) {
    int hh, mm, ss;
    scanf("%d:%d:%d%*c", &hh, &mm, &ss);
    int seconds = 60 * 60 * hh + 60 * mm + ss;
    events.emplace_back(seconds, 0, i);
    events.emplace_back(seconds + t - 1, 1, i);
  }
  sort(events.begin(), events.end());
  int distinct = 0;
  int next_id = 1;
  bool good = false;
  for (auto &each : events) {
    int p, type, id;
    tie(p, type, id) = each;
    if (type == 0) {
      if (distinct == m) {
        ans[id] = next_id - 1;
      } else {
        ans[id] = next_id++;
        distinct++;
      }
      app[ans[id]]++;
    } else {
      app[ans[id]]--;
      if (app[ans[id]] == 0) {
        distinct--;
      }
    }
    if (distinct == m) {
      good = true;
    }
  }
  if (good) {
    printf("%d\n", next_id - 1);
    for (int i = int(0); i < int(n); i++) {
      printf("%d\n", ans[i]);
    }
  } else {
    puts("No solution");
  }
  return 0;
}
