#include <bits/stdc++.h>
using namespace std;
int O[30000];
int main() {
  int N, M, T;
  scanf("%d %d %d ", &N, &M, &T);
  vector<pair<int, int> > S;
  for (int i = 0; i < (int)(N); i++) {
    int h, m, s;
    scanf("%d:%d:%d ", &h, &m, &s);
    int v = s + 60 * m + 3600 * h;
    S.push_back(make_pair(v, 1));
    S.push_back(make_pair(v + T, 0));
  }
  sort(S.begin(), S.end());
  set<int> second;
  queue<int> Q;
  vector<int> Q2;
  int ind = 1;
  bool ok = false;
  for (typeof((S).begin()) v = (S).begin(); v != (S).end(); ++v) {
    if (M == (int)second.size()) ok = true;
    bool in = v->second;
    if (!in) {
      O[Q.front()]--;
      if (O[Q.front()] == 0) second.erase(Q.front());
      Q.pop();
    } else {
      if (M == (int)second.size()) {
        second.insert(ind - 1);
        Q.push(ind - 1);
        Q2.push_back(ind - 1);
        O[ind - 1]++;
      } else {
        second.insert(ind);
        Q.push(ind);
        Q2.push_back(ind);
        O[ind]++;
        ind++;
      }
    }
  }
  if (!ok)
    printf("No solution\n");
  else {
    printf("%d\n", ind - 1);
    for (int i = 0; i < (int)(Q2.size()); i++) printf("%d\n", Q2[i]);
  }
  return 0;
}
