#include <bits/stdc++.h>
using namespace std;
int get_sec(int h, int m, int s) { return 3600 * h + 60 * m + s; }
void solve() {
  int n, m, t;
  cin >> n >> m >> t;
  bool has_max = false;
  vector<int> s(n);
  vector<vector<int> > all(n);
  vector<int> pos(n);
  vector<int> ans(n);
  int give = 0;
  for (int i = 0; i < n; ++i) {
    string t;
    cin >> t;
    string h = t.substr(0, 2), m = t.substr(3, 5), sec = t.substr(6, 8);
    s[i] = get_sec(atoi(h.c_str()), atoi(m.c_str()), atoi(sec.c_str()));
  }
  deque<int> q;
  int has = 0;
  for (int i = 0; i < n; ++i) {
    int exp = s[i] - t;
    while (!q.empty()) {
      int v = q.front();
      if (pos[v] == all[v].size() || all[v][pos[v]] > exp) break;
      q.pop_front();
      ++pos[v];
      if (pos[v] == all[v].size()) --has;
    }
    if (has < m) {
      ++has;
      all[give].push_back(s[i]);
      q.push_back(give);
      ans[i] = give;
      ++give;
    } else {
      int v = q.back();
      all[v].push_back(s[i]);
      q.push_back(v);
      ans[i] = v;
    }
    if (has == m) has_max = true;
  }
  if (!has_max)
    cout << "No solution";
  else {
    cout << give << "\n";
    for (int i = 0; i < n; ++i) cout << ans[i] + 1 << "\n";
  }
}
int main(int argc, char *argv[]) {
  std::ios_base::sync_with_stdio(false);
  solve();
  return 0;
}
