#include <bits/stdc++.h>
using namespace std;
int n, m, T, ans, t[111111], cur, a[22222], last;
vector<vector<int> > v;
string s;
bool ok = false;
map<int, int> ma;
int main() {
  cin >> n >> m >> T;
  v.resize(86444, vector<int>());
  for (int i = 0; i < n; ++i) {
    cin >> s;
    int ho, mi, se;
    ho = (s[0] - '0') * 10 + (s[1] - '0');
    mi = (s[3] - '0') * 10 + (s[4] - '0');
    se = (s[6] - '0') * 10 + (s[7] - '0');
    v[(ho * 60 + mi) * 60 + se].push_back(i);
  }
  for (int i = 0; i <= 86400; ++i) {
    if (i - T >= 0)
      for (int j = 0; j < v[i - T].size(); ++j) {
        ma[a[v[i - T][j]]]--;
        if (ma[a[v[i - T][j]]] == 0) cur--;
      }
    for (int j = 0; j < v[i].size(); ++j) {
      if (cur == m) {
        ma[last]++;
        a[v[i][j]] = last;
      } else {
        cur++;
        if (cur == m) ok = true;
        ma[++ans] = 1;
        a[v[i][j]] = ans;
        last = ans;
      }
    }
  }
  if (!ok)
    cout << "No solution\n";
  else {
    cout << ans << endl;
    for (int i = 0; i < n; ++i) cout << a[i] << endl;
  }
  return 0;
}
