#include <bits/stdc++.h>
using namespace std;
int N, M, T;
int timeToInt(const char* s) {
  int ret = 0;
  ret += 36000 * (s[0] - '0');
  ret += 3600 * (s[1] - '0');
  ret += 600 * (s[3] - '0');
  ret += 60 * (s[4] - '0');
  ret += 10 * (s[6] - '0');
  ret += 1 * (s[7] - '0');
  return ret;
}
int main() {
  deque<pair<int, int> > curr;
  queue<int> events;
  queue<int> users;
  char str[10];
  scanf("%d %d %d", &N, &M, &T);
  while (N--) {
    scanf("%s", str);
    events.push(timeToInt(str));
  }
  int tot_users = 0;
  bool reach = false;
  while (not events.empty()) {
    int t = events.front();
    events.pop();
    while (not curr.empty() and t > curr.front().first) curr.pop_front();
    if (curr.size() == M) {
      curr.back().first = t + T - 1;
      users.push(curr.back().second);
    } else {
      curr.push_back(make_pair(t + T - 1, ++tot_users));
      users.push(tot_users);
      if (curr.size() == M) reach = true;
    }
  }
  if (not reach)
    printf("No solution\n");
  else {
    printf("%d\n", tot_users);
    while (not users.empty()) {
      printf("%d\n", users.front());
      users.pop();
    }
  }
  return 0;
}
