#include <bits/stdc++.h>
#pragma comment(linker, "/stack:256000000")
using namespace std;
const int N = 24 * 60 * 60 + 100;
int ent[N], ex[N];
int main() {
  int n, m, T;
  scanf("%d%d%d\n", &n, &m, &T);
  for (int(i) = 0; (i) < (n); (i)++) {
    int hr, min, sec;
    scanf("%d:%d:%d\n", &hr, &min, &sec);
    int tm = sec + 60 * min + 60 * 60 * hr;
    ent[tm]++;
  }
  int cur = 0;
  int id_last = 0;
  int time_last = 0;
  bool reach = 0;
  vector<int> ans;
  for (int(i) = 0; (i) < (N); (i)++) {
    cur -= ex[i];
    for (int(j) = 0; (j) < (ent[i]); (j)++) {
      if (cur < m) {
        id_last++;
        time_last = i;
        ex[time_last + T]++;
        cur++;
        if (cur == m) {
          reach = 1;
        }
      } else if (cur == m) {
        ex[time_last + T]--;
        time_last = i;
        ex[time_last + T]++;
      }
      ans.push_back(id_last);
    }
  }
  if (!reach) {
    puts("No solution");
  } else {
    if (ans.empty()) {
      cout << 0 << endl;
    } else {
      cout << ans.back() << endl;
      for (int(i) = 0; (i) < ((int)(ans).size()); (i)++) printf("%d\n", ans[i]);
    }
  }
  return 0;
}
