#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
template <class T>
void dbs(string str, T t) {
  cout << str << " : " << t << endl;
}
template <class T, class... second>
void dbs(string str, T t, second... s) {
  int idx = str.find(',');
  cout << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
template <class second, class T>
ostream& operator<<(ostream& os, const pair<second, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class second, class T>
ostream& operator<<(ostream& os, const map<second, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void prc(T a, T b) {
  cout << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cout << ", ";
    cout << *i;
  }
  cout << "]";
  cout << endl;
}
const int N = 86400;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, M, T;
  cin >> n >> M >> T;
  vector<int> a(N + 1);
  for (int i = (0); i <= (n - 1); ++i) {
    string s;
    cin >> s;
    int x = stoi(s.substr(0, 2)) * 3600 + stoi(s.substr(3, 2)) * 60 +
            stoi(s.substr(6, 2));
    a[x + 1]++;
  }
  vector<vector<int> > ans(N + 1);
  int ctr = 0;
  map<int, int> s;
  for (int i = (1); i <= (T); ++i) {
    for (int it = (1); it <= (a[i]); ++it) {
      if (int(s.size()) < M) ++ctr;
      ans[i].push_back(ctr);
      s[ctr]++;
    }
  }
  bool can = false;
  can |= int(s.size()) == M;
  for (int i = (T + 1); i <= (N); ++i) {
    for (int x : ans[i - T]) {
      s[x]--;
      if (s[x] == 0) s.erase(x);
    }
    for (int it = (1); it <= (a[i]); ++it) {
      if (int(s.size()) < M) ++ctr;
      ans[i].push_back(ctr);
      s[ctr]++;
    }
    can |= int(s.size()) == M;
  }
  if (not can) return cout << "No solution\n", 0;
  cout << ctr << "\n";
  for (int i = (1); i <= (N); ++i)
    for (int j : ans[i]) cout << j << "\n";
  return 0;
}
