#include <bits/stdc++.h>
using namespace std;
multiset<int> S;
char W[1000];
vector<int> ans;
int num;
int main() {
  int n, m, t;
  scanf("%d%d%d", &n, &m, &t);
  int mm = 0;
  for (int i = 0; i < n; i++) {
    scanf("%s", W);
    int ki = 36000 * (W[0] - '0') + 3600 * (W[1] - '0') + 600 * (W[3] - '0') +
             60 * (W[4] - '0') + 10 * (W[6] - '0') + W[7] - '0';
    while (S.size() > 0 && (*S.begin()) + t <= ki) S.erase(S.begin());
    if ((int)S.size() < m) {
      S.insert(ki);
      num++;
    } else {
      auto tp = S.end();
      tp--;
      S.erase(tp);
      S.insert(ki);
    }
    ans.push_back(num);
    mm = max(mm, (int)S.size());
  }
  if (mm < m) {
    printf("No solution\n");
  } else {
    printf("%d\n", num);
    for (int x : ans) printf("%d\n", x);
  }
}
