#include <bits/stdc++.h>
using namespace std;
int s2i(string &str, int i) {
  int result = 0;
  result += 10 * (str[i] - '0');
  result += str[i + 1] - '0';
  return result;
}
const int maxt = 90000;
int main() {
  int n, M, T;
  cin >> n >> M >> T;
  vector<vector<int>> in(2 * maxt);
  vector<vector<int>> out(2 * maxt);
  vector<pair<int, int>> ranges(n);
  for (int i = 0; i < n; ++i) {
    string time;
    cin >> time;
    int t = s2i(time, 0) * 60 * 60 + s2i(time, 3) * 60 + s2i(time, 6);
    in[t].push_back(i);
    out[t + T].push_back(i);
    ranges[i] = make_pair(t, t + T);
  }
  set<int> ids;
  map<int, int> del;
  vector<int> answer(n);
  int ptr = 1;
  bool good = false;
  for (int t = 0; t < maxt; ++t) {
    if (ids.size() == M) good = true;
    for (int i = 0; i < out[t].size(); ++i) {
      int ind = out[t][i];
      del[answer[ind]]--;
      if (del[answer[ind]] == 0) ids.erase(answer[ind]);
    }
    for (int i = 0; i < in[t].size(); ++i) {
      int ind = in[t][i];
      if (ids.size() == M) {
        auto it = ids.end();
        --it;
        answer[ind] = *it;
      } else {
        answer[ind] = ptr++;
        ids.insert(answer[ind]);
      }
      del[answer[ind]]++;
    }
  }
  if (good) {
    cout << ptr - 1 << endl;
    for (int i = 0; i < n; ++i) cout << answer[i] << endl;
  } else
    cout << "No solution" << endl;
  return 0;
}
