#include <bits/stdc++.h>
using namespace std;
int n, m, t, s[100100], id[100100];
int read() {
  int h, m, s;
  scanf("%d:%d:%d", &h, &m, &s);
  return h * 3600 + m * 60 + s;
}
int main() {
  scanf("%d %d %d", &n, &m, &t);
  for (int i = 0; i < n; i++) s[i] = read();
  int ans = 0, fg = 1;
  deque<int> dq;
  for (int i = 0; i < n; i++) {
    while (!dq.empty() && s[dq.front()] + t <= s[i]) dq.pop_front();
    if (dq.size() == m)
      id[i] = id[dq.back()], dq.pop_back(), dq.push_back(i);
    else {
      dq.push_back(i), id[i] = ++ans;
      if (dq.size() == m) fg = 0;
    }
  }
  if (fg)
    puts("No solution");
  else {
    printf("%d\n", ans);
    for (int i = 0; i < n; i++) printf("%d\n", id[i]);
  }
  return 0;
}
