#include <bits/stdc++.h>
using namespace std;
int n, M, T;
struct event {
  int id, time;
  bool prior;
} a[50500];
bool cmp(event a, event b) {
  if (a.time != b.time) return a.time < b.time;
  return a.prior < b.prior;
}
multiset<pair<int, int> > s;
int f[20500];
int main() {
  scanf("%d%d%d", &n, &M, &T);
  for (int i = 0; i < n; ++i) {
    int h, m, s;
    scanf("%d:%d:%d", &h, &m, &s);
    int time = h * 3600 + m * 60 + s;
    a[i + i].id = i;
    a[i + i].prior = 0;
    a[i + i].time = time;
    a[i + i + 1].id = i;
    a[i + i + 1].prior = 1;
    a[i + i + 1].time = time + T - 1;
  }
  sort(a, a + (n << 1), cmp);
  int k = 0;
  int id = 1;
  vector<int> ans;
  int last;
  bool solution = false;
  for (int i = 0; i < (n << 1); ++i) {
    event cur = a[i];
    if (!cur.prior) {
      if (k < M) {
        ans.push_back(id);
        s.insert(make_pair(id, 1));
        k++;
        if (k == M) solution = true;
        f[cur.id] = id;
        last = id;
        ++id;
      } else {
        solution = true;
        pair<int, int> p = *s.lower_bound(make_pair(last, 0));
        s.erase(s.find(p));
        ans.push_back(p.first);
        p.second++;
        s.insert(p);
        f[cur.id] = p.first;
        last = p.first;
      }
    } else {
      int g = f[cur.id];
      pair<int, int> p = *s.lower_bound(make_pair(g, 0));
      s.erase(p);
      p.second--;
      if (p.second > 0) {
        s.insert(p);
      } else {
        k--;
      }
    }
  }
  if (!solution) {
    printf("No solution\n");
    return 0;
  }
  printf("%d\n", id - 1);
  for (int i = 0; i < ans.size(); ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
