#include <bits/stdc++.h>
using namespace std;
int ans[20000];
vector<int> q[86400];
int main() {
  int n, m, T;
  scanf("%d%d%d", &n, &m, &T);
  for (int i = 0; i < n; ++i) {
    int hr, mn, se;
    scanf("%d:%d:%d", &hr, &mn, &se);
    int tm = hr * 60 * 60 + mn * 60 + se;
    q[tm].push_back(i);
  }
  deque<pair<int, int> > on;
  int cnt = 0;
  bool ok = false;
  for (int t = 0; t < 86400; ++t) {
    while (!on.empty() && on.front().first + T == t) {
      on.pop_front();
    }
    for (int k = 0; k < q[t].size(); ++k) {
      if (on.size() < m) {
        int p = q[t][k];
        int id = ++cnt;
        ans[p] = id;
        on.push_back(pair<int, int>(t, id));
        ok |= on.size() == m;
      } else {
        int p = q[t][k];
        int id = on.back().second;
        ans[p] = id;
        on.pop_back();
        on.push_back(pair<int, int>(t, id));
      }
    }
  }
  if (!ok) {
    printf("No solution\n");
  } else {
    printf("%d\n", cnt);
    for (int i = 0; i < n; ++i) {
      printf("%d\n", ans[i]);
    }
  }
  return 0;
}
