#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000,100000000000")
using namespace std;
const double eps = 1E-9;
const double Exp = 2.718281828459045;
const double Pi = 3.1415926535897932;
const int NMAX = 100000 + 5;
const int MMAX = 100000 + 5;
const int INF = 1000000000;
const int BS = 1000000007;
template <typename T>
inline T abs(const T a) {
  if (a < 0) return -a;
  return a;
}
template <typename T>
inline T sqr(const T& a) {
  return a * a;
}
int main() {
  ios::sync_with_stdio(false);
  int n, m, t;
  cin >> n >> m >> t;
  char c;
  int i, j, k;
  int hh, mm, ss;
  pair<int, int> a[NMAX];
  for (i = 1; i <= n; i++) {
    cin >> hh >> c >> mm >> c >> ss;
    a[i].first = hh * 3600 + 60 * mm + ss;
    a[i].second = i;
  }
  sort(a + 1, a + n + 1);
  int open = 1;
  int close = 1;
  int num = 0;
  int cur;
  bool was = 0;
  static int ans[NMAX];
  map<int, int> cnt;
  set<pair<int, int> > st;
  set<pair<int, int> >::iterator it;
  for (cur = 0; cur <= 86400; cur++) {
    if (int((cnt).size()) == m) was = 1;
    while (open <= n && a[open].first <= cur) {
      if (int((cnt).size()) < m)
        ++num;
      else
        was = 1;
      ans[a[open].second] = num;
      st.insert(make_pair(open, num));
      cnt[num]++;
      open++;
    }
    while (close <= n && a[close].first + t - 1 <= cur) {
      it = st.lower_bound(make_pair(close, -1));
      cnt[it->second]--;
      if (cnt[it->second] == 0) cnt.erase(it->second);
      st.erase(it);
      close++;
    }
  }
  if (!was)
    cout << "No solution" << endl;
  else {
    cout << num << endl;
    for (i = 1; i <= n; i++) {
      cout << ans[i] << endl;
    }
  }
  return 0;
}
