#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& fout, const vector<T>& vec) {
  for (size_t i = 0; i < vec.size(); ++i) {
    fout << vec[i] << ' ';
  }
  return fout;
}
template <class T>
istream& operator>>(istream& fin, vector<T>& vec) {
  for (size_t i = 0; i < vec.size(); ++i) {
    cin >> vec[i];
  }
  return fin;
}
int n, m, t;
multiset<pair<int, int>> cur;
int ans[20000];
int main() {
  scanf("%d %d %d\n", &n, &m, &t);
  int maxcur = 0;
  int cnt = 0;
  for (int i = 0; i < int(n); ++i) {
    int hh, mm, ss;
    scanf("%d:%d:%d\n", &hh, &mm, &ss);
    int tt = (hh * 60 + mm) * 60 + ss;
    while (cur.size() && cur.begin()->first <= tt) {
      cur.erase(cur.begin());
    }
    if (cur.size() < (uint32_t)m) {
      ++cnt;
      ans[i] = cnt;
      cur.insert(make_pair(tt + t, cnt));
    } else {
      auto p = --cur.end();
      int c = p->second;
      cur.erase(p);
      ans[i] = c;
      cur.insert(make_pair(tt + t, c));
    }
    maxcur = max(maxcur, (int)cur.size());
  }
  if (maxcur < m) {
    puts("No solution");
  } else {
    printf("%d\n", cnt);
    for (int i = 0; i < int(n); ++i) {
      printf("%d\n", ans[i]);
    }
  }
  return 0;
}
