#include <bits/stdc++.h>
using namespace std;
const int maxn = 20200, maxt = 86400;
int Q[2 * maxt + 100], stop[maxn], cInd;
int n, m, t;
bool works;
deque<int> ans, online;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> t;
  for (int i = 0; i < n; i++) {
    string times;
    cin >> times;
    Q[3600 * (10 * (times[0] - '0') + (times[1] - '0')) +
      60 * (10 * (times[3] - '0') + (times[4] - '0')) + 10 * (times[6] - '0') +
      (times[7] - '0')]++;
  }
  for (int i = 0; i < maxt; i++) {
    while (!online.empty() && stop[online.back()] == i) {
      online.pop_back();
    }
    int cDiff = online.size();
    if (!works && cDiff == m) {
      works = true;
    }
    if (cDiff + Q[i] > m) {
      int rep = Q[i] + cDiff - m;
      while (cDiff < m) {
        ans.push_front(cInd);
        online.push_front(cInd);
        stop[cInd] = i + t;
        cInd++;
        cDiff++;
      }
      for (int j = 0; j < rep; j++) {
        ans.push_front(online.front());
      }
      stop[online.front()] = i + t;
    } else {
      for (int j = 0; j < Q[i]; j++) {
        ans.push_front(cInd);
        online.push_front(cInd);
        stop[cInd] = i + t;
        cInd++;
      }
    }
  }
  if (!works) {
    cout << "No solution\n";
    return 0;
  }
  cout << cInd << '\n';
  for (int i = n - 1; i >= 0; i--) cout << ans[i] + 1 << '\n';
  return 0;
}
