#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 50;
map<int, vector<int> > f;
int r2(string& s, int p) {
  int r = s[p] - '0';
  r *= 10;
  r += s[p + 1] - '0';
  return r;
}
int s_to_t(string& s) {
  int t = r2(s, 0) * 3600;
  t += r2(s, 3) * 60;
  t += r2(s, 6);
  return t;
}
int ans[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  int n, M, T;
  cin >> n >> M >> T;
  bool p = false;
  map<int, int> off;
  string s;
  int R = 0;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    int t = s_to_t(s);
    while (off.size() > 0 && off.begin()->second <= t) {
      off.erase(off.begin());
    }
    if (off.size() < M) {
      ++R;
      ans[i] = R;
      off[R] = t + T;
      if (off.size() == M) p = true;
    } else {
      ans[i] = ans[i - 1];
      off[R] = t + T;
    }
  }
  if (!p) {
    cout << "No solution\n";
    return 0;
  }
  cout << R << '\n';
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << '\n';
  }
}
