#include <bits/stdc++.h>
using namespace std;
inline long long in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline string get() {
  char ch[2000010];
  scanf("%s", ch);
  return ch;
}
inline void read(long long *a, long long n) {
  for (long long i = 0; i < n; i++) a[i] = in();
}
template <class blank>
inline void out(blank x) {
  cout << x << "\n";
  exit(0);
}
const long long maxn = 5e5 + 10;
const long long maxm = 1e6 + 10;
const long long maxlg = 21;
const long long base = 29;
const long long mod = 1e9 + 7;
const long long INF = 1e18 + 10;
const long long SQ = 317;
long long a[maxn];
long long sz;
vector<long long> ids;
long long cnt[maxn];
long long tot = 0;
int32_t main() {
  long long n = in(), m = in(), t = in();
  for (long long i = 0; i < n; i++) {
    long long hour, minute, second;
    scanf("%lld:%lld:%lld", &hour, &minute, &second);
    second += 60 * minute + 3600 * hour;
    a[i] = second;
  }
  long long cur = 0;
  deque<pair<long long, long long> > q;
  bool fl = false;
  for (long long i = 0; i <= 86400 * 2; i++) {
    while (q.size() && q.front().first == i - t) {
      cnt[q.front().second]--;
      if (!cnt[q.front().second]) tot--;
      q.pop_front();
    }
    while (cur < n && a[cur] == i) {
      long long newId = tot == m ? q.back().second : sz++;
      ++cnt[newId];
      if (cnt[newId] == 1) tot++;
      q.push_back({a[cur++], newId});
      ids.push_back(newId + 1);
    }
    if (tot == m) fl = true;
  }
  if (!fl) out("No solution");
  cout << sz << "\n";
  for (long long i = 0; i < ids.size(); i++) cout << ids[i] << "\n";
}
