#include <bits/stdc++.h>
using namespace std;
struct user {
  int id;
  int endtime;
  user() : id(0), endtime(0) {}
  user(int Id, int Endtime) : id(Id), endtime(Endtime) {}
};
bool comp(user* f, user* s) { return f->endtime > s->endtime; }
void push(vector<user*>& v, user* u) {
  v.push_back(u);
  std::push_heap(v.begin(), v.end(), comp);
}
void pop(vector<user*>& v) {
  std::pop_heap(v.begin(), v.end(), comp);
  v.pop_back();
}
user* top(vector<user*>& v) {
  if (v.empty()) return 0;
  return v.front();
}
int main() {
  int n, m, t;
  scanf("%d %d %d", &n, &m, &t);
  vector<user*> heap;
  heap.reserve(n + 100);
  vector<int> count(n + 100, 0);
  vector<int> req(n + 100, 0);
  int r = 0;
  bool havesolution = false;
  int diff = 0;
  for (int i = 0; i < n; ++i) {
    int hh, mm, ss;
    scanf("%d:%d:%d", &hh, &mm, &ss);
    int time = ss + 60 * (mm + 60 * hh);
    user* utop = top(heap);
    while (utop != 0 && utop->endtime < time) {
      --(count[utop->id]);
      if (!(count[utop->id])) --diff;
      pop(heap);
      utop = top(heap);
    }
    if (diff == m) {
      ++(count[r]);
      push(heap, new user(r, time + t - 1));
    } else {
      if (diff == (m - 1)) {
        havesolution = true;
      }
      ++r;
      ++(count[r]);
      push(heap, new user(r, time + t - 1));
      ++diff;
    }
    req[i] = r;
  }
  if (!havesolution) {
    printf("No solution");
  } else {
    printf("%d\n", r);
    for (int i = 0; i < n; ++i) {
      printf("%d\n", req[i]);
    }
  }
  return 0;
}
