#include <bits/stdc++.h>
using namespace std;
vector<int> sol;
int n, m, T, h, mi, cnt, fndm, v[1000100], sec;
char ch;
int main() {
  cin >> n >> m >> T;
  for (int i = 1; i <= n; ++i) {
    cin >> h;
    cin >> ch;
    h *= 3600;
    cin >> mi;
    cin >> ch;
    mi *= 60;
    cin >> sec;
    v[i] = h + mi + sec;
  }
  int la = 0;
  int lt = 0;
  int user = 0;
  multiset<int> hm;
  for (int i = 1; i <= n; ++i) {
    while (!hm.empty() && *hm.begin() < v[i]) hm.erase(hm.begin());
    if (hm.size() == m) {
      sol.push_back(user);
      if (hm.count(v[i - 1] + T - 1)) hm.erase(hm.find(v[i - 1] + T - 1));
    } else
      sol.push_back(++user);
    hm.insert(v[i] + T - 1);
    if (hm.size() == m) fndm = 1;
  }
  if (!fndm) {
    cout << "No solution";
    return 0;
  }
  cout << user << "\n";
  for (vector<int>::iterator it = sol.begin(); it != sol.end(); it++)
    cout << *it << "\n";
  return 0;
}
