#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, t, h, mn, s;
  cin >> n >> m >> t;
  int r = 0;
  char c;
  deque<long long> q;
  vector<int> a;
  bool flag = false;
  while (n--) {
    cin >> h >> c >> mn >> c >> s;
    long long ts = h * 3600 + mn * 60 + s;
    while (!q.empty() && q.front() <= ts) q.pop_front();
    if (q.size() == m)
      q.pop_back();
    else
      ++r;
    a.push_back(r);
    q.push_back(t + ts);
    if (q.size() == m) flag = true;
  }
  if (flag) {
    cout << r << "\n";
    for (auto i : a) {
      cout << i << "\n";
    }
  } else
    cout << "No solution";
}
