#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:836777216")
using namespace std;
int n, t, m;
int nextId = 0;
int max_online = 0;
int cur_online = 0;
deque<pair<int, int> > id_q;
int cnt[86400];
vector<int> answer;
int main(void) {
  memset((cnt), (0), sizeof((cnt)));
  scanf("%d%d%d", &n, &m, &t);
  for (int(i) = 0; (i) < (n); (i)++) {
    int hh, mm, ss;
    scanf("%d:%d:%d", &hh, &mm, &ss);
    int time_ = hh * 60 * 60 + mm * 60 + ss;
    cnt[time_]++;
  }
  for (int(i) = 0; (i) < (86400); (i)++) {
    while ((int)(id_q).size() && (id_q.front().second + t == i)) {
      id_q.pop_front();
      cur_online--;
    }
    if (cnt[i]) {
      for (int(j) = 0; (j) < (cnt[i]); (j)++) {
        if (cur_online < m) {
          id_q.push_back(make_pair(nextId++, i));
          cur_online++;
          max_online = max(max_online, cur_online);
          answer.push_back(nextId);
        } else {
          id_q.back().second = i;
          answer.push_back(nextId);
        }
      }
    }
  }
  if (max_online != m) {
    printf("No solution\n");
  } else {
    printf("%d\n", nextId);
    for (int(i) = 0; (i) < ((int)(answer).size()); (i)++) {
      printf("%d\n", answer[i]);
    }
  }
  return 0;
}
