#include <bits/stdc++.h>
using namespace std;
template <class T>
void printImpl(const vector<T>& coll) {
  copy(coll.begin(), coll.end(), ostream_iterator<T>(cout, " "));
  cout << endl;
}
template <class T, int N>
void printImpl(T (&coll)[N]) {
  copy(coll, coll + N, ostream_iterator<T>(cout, " "));
  cout << endl;
}
template <class Key, class Value>
void printImpl(const map<Key, Value>& data) {
  typename map<Key, Value>::const_iterator it;
  for (it = data.begin(); it != data.end(); ++it) {
    cout << it->first << ":" << it->second << endl;
  }
}
template <class T>
void printImpl(const T& data) {
  cout << data << endl;
}
int main() {
  int N, M, T;
  cin >> N >> M >> T;
  if (N < M) {
    cout << "No solution" << endl;
    return 0;
  }
  const int MT = 86400;
  vector<vector<int> > added(MT), left(MT);
  vector<int> res(N);
  for (int i = 0; i < (N); ++i) {
    int hh, mm, ss;
    char c;
    cin >> hh >> c >> mm >> c >> ss;
    int start = hh * 3600 + mm * 60 + ss;
    added[start].push_back(i);
    left[start + T].push_back(i);
  }
  multiset<int> active;
  set<int> uniqueActive;
  int lastAdded = -1;
  int ix = 0;
  int maxReached = -1;
  for (int t = 0; t < MT; ++t) {
    for (int ii = 0; ii < left[t].size(); ++ii) {
      int leftId = left[t][ii];
      active.erase(active.find(res[leftId]));
      if (active.find(res[leftId]) == active.end()) {
        uniqueActive.erase(res[leftId]);
      }
    }
    for (int ii = 0; ii < added[t].size(); ++ii) {
      int reqId = added[t][ii];
      if (uniqueActive.size() < M) {
        active.insert(ix);
        uniqueActive.insert(ix);
        res[reqId] = ix;
        lastAdded = ix;
        ++ix;
      } else {
        active.insert(lastAdded);
        res[reqId] = lastAdded;
      }
      maxReached = max<int>(maxReached, uniqueActive.size());
    }
  }
  if (maxReached < M) {
    cout << "No solution" << endl;
    return 0;
  }
  cout << ix << endl;
  for (int i = 0; i < (N); ++i) {
    cout << res[i] + 1 << endl;
  }
  return 0;
}
