#include <bits/stdc++.h>
using namespace std;
const int MAX_T = 86400;
int mas[MAX_T + 10];
int CC[MAX_T + 10];
int main() {
  ios::sync_with_stdio(0);
  int n, m, t;
  cin >> n >> m >> t;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    int hh = (s[0] - '0') * 10 + (s[1] - '0');
    int mm = (s[3] - '0') * 10 + (s[4] - '0');
    int ss = (s[6] - '0') * 10 + (s[7] - '0');
    ss += mm * 60;
    ss += hh * 60 * 60;
    CC[ss]++;
    mas[ss]++;
    mas[ss + t]--;
  }
  for (int i = 1; i <= MAX_T; ++i) mas[i] += mas[i - 1];
  if (*max_element(mas, mas + MAX_T) < m) {
    puts("No solution");
    return 0;
  }
  int r = 0;
  vector<int> res;
  memset(mas, 0, sizeof mas);
  int pp = 0;
  for (int i = 0; i < MAX_T; ++i) {
    if (i > 0) mas[i] += mas[i - 1];
    int cc = CC[i];
    while (cc-- > 0) {
      if (mas[i] + 1 <= m) {
        mas[i]++, mas[i + t]--;
        res.push_back(++r);
        pp = i;
      } else {
        mas[pp + t]++;
        mas[i + t]--;
        res.push_back(r);
        pp = i;
      }
    }
  }
  cout << r << "\n";
  for (int i = 0; i < n; ++i) cout << res[i] << "\n";
  return 0;
}
