#include <bits/stdc++.h>
using namespace std;
int answer, users, n, m, t, i, FreeID, hours, minutes, seconds;
bool completed;
pair<int, pair<int, int> > events[300000];
int id[300000];
int c[300000];
void work() {
  scanf("%d%d%d", &n, &m, &t);
  for (i = (1); i <= (n); i++) {
    char u;
    scanf("%d%c%d%c%d", &hours, &u, &minutes, &u, &seconds);
    seconds += 3600 * hours + 60 * minutes;
    events[2 * (i - 1) + 1] = make_pair(seconds, make_pair(i, 1));
    events[2 * i] = make_pair(seconds + t, make_pair(i, 2));
  }
  sort(events + 1, events + 2 * n + 1);
  for (i = (1); i <= (2 * n); i++) {
    if (events[i].second.second == 1) {
      if (users == m) {
        id[events[i].second.first] = FreeID;
        c[id[events[i].second.first]]++;
      } else {
        answer++;
        FreeID = answer;
        id[events[i].second.first] = answer;
        c[id[events[i].second.first]]++;
        users++;
      }
      if (users == m) {
        completed = true;
      }
    } else {
      c[id[events[i].second.first]]--;
      if (c[id[events[i].second.first]] == 0) {
        users--;
      }
    }
  }
  if (completed) {
    printf("%d\n", answer);
    for (i = (1); i <= (n); i++) {
      printf("%d\n", id[i]);
    }
  } else {
    cout << "No solution" << endl;
  }
}
int main() {
  work();
  return 0;
}
