#include <bits/stdc++.h>
using namespace std;
int tym(string s) {
  return stoi(s.substr(0, 2)) * 3600 + stoi(s.substr(3, 2)) * 60 +
         stoi(s.substr(6, 2));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, t;
  cin >> n >> m >> t;
  vector<int> ans(n);
  bool achieved = false;
  int R = 0;
  set<pair<int, int> > shesh;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int x = tym(s);
    while (!shesh.empty() && shesh.begin()->first < x) {
      shesh.erase(shesh.begin());
    }
    if (shesh.size() == m) {
      shesh.erase(prev(shesh.end()));
    } else {
      R++;
    }
    shesh.emplace(x + t - 1, R);
    ans[i] = R;
    if (shesh.size() == m) {
      achieved = true;
    }
  }
  if (!achieved) {
    cout << "No solution\n";
    return 0;
  }
  cout << R << "\n";
  for (int x : ans) cout << x << "\n";
  return 0;
}
