#include <bits/stdc++.h>
using namespace std;
int input() {
  int a, b, c;
  char d;
  cin >> a >> d >> b >> d >> c;
  return a * 3600 + b * 60 + c;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, M, T;
  cin >> n >> M >> T;
  deque<pair<int, int> > Q;
  int num = 0;
  int good = 0;
  vector<int> res;
  for (int i = 0; i < n; i++) {
    int t = input();
    while (!Q.empty() && t - Q.front().first >= T) Q.pop_front();
    if ((int((Q).size())) < M) {
      num++;
      res.push_back(num);
      Q.push_back(make_pair(t, num));
      if ((int((Q).size())) == M) good = 1;
    } else {
      int now = Q.back().second;
      res.push_back(now);
      Q.pop_back();
      Q.push_back(make_pair(t, now));
    }
  }
  if (good) {
    cout << num << '\n';
    for (auto x : res) cout << x << '\n';
  } else
    cout << "No solution\n";
  return 0;
}
