#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, t;
  bool ok = false;
  scanf("%d%d%d", &n, &m, &t);
  int total = 0;
  int last = 0;
  list<int> l;
  vector<int> res;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int h = (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';
    mm += h * 60;
    ss += mm * 60;
    while (total > 0 && l.front() <= ss) {
      total--;
      l.pop_front();
    }
    if (total < m) {
      total++;
      l.push_back(ss + t);
      last++;
    } else {
      l.back() = ss + t;
    }
    if (total == m) ok = true;
    res.push_back(last);
  }
  if (!ok) {
    printf("No solution");
    return 0;
  }
  printf("%d\n", last);
  for (int i = 0; i < n; i++) printf("%d\n", res[i]);
  return 0;
}
