#include <bits/stdc++.h>
using namespace std;
const int maxn = ((int)5000) + 5;
int nxt = 1;
set<pair<long long int, int>> pq;
long long int toSec(string h) {
  int hour = stoi(h.substr(0, 2));
  int min = stoi(h.substr(3, 2));
  int sec = stoi(h.substr(6, 2));
  return hour * 3600 + min * 60 + sec;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  bool ok = false;
  int n, m, t;
  cin >> n >> m >> t;
  vector<int> res;
  for (int i = 0; i < n; i++) {
    string time;
    cin >> time;
    long long int sec = toSec(time);
    while (pq.size() > 0 && pq.begin()->first + t <= sec) {
      pq.erase(pq.begin());
    }
    if (pq.size() == m) {
      ok = true;
      auto t = pq.end();
      advance(t, -1);
      auto temp = *t;
      pq.erase(t);
      pq.insert(make_pair(sec, temp.second));
      res.push_back(temp.second);
    } else {
      res.push_back(nxt);
      pq.insert(make_pair(sec, nxt++));
    }
    if (pq.size() == m) {
      ok = true;
    }
  }
  if (!ok) {
    cout << "No solution";
  } else {
    cout << nxt - 1 << "\n";
    for (int g : res) {
      cout << g << "\n";
    }
  }
  return 0;
}
