#include <bits/stdc++.h>
using namespace std;
struct node {
  int id;
  long long time;
  bool in;
};
bool operator<(node n1, node n2) {
  if (n1.time != n2.time) return n1.time > n2.time;
  if (n2.in && !n1.in) return 1;
  if (n1.in && !n2.in) return 0;
  return n1.id > n2.id;
}
int main() {
  long long n, m, t;
  cin >> n >> m >> t;
  int ans = 0;
  int cnt = 0;
  bool fnd = 0;
  vector<int> fans(n);
  priority_queue<node> myq;
  vector<int> out(n, -1);
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    node now;
    now.id = i;
    now.time = 0;
    now.in = 1;
    long long h = s[0] - '0';
    h *= 10;
    h += s[1] - '0';
    long long m = 10 * (s[3] - '0') + s[4] - '0';
    long long sec = 10 * (s[6] - '0') + s[7] - '0';
    now.time = 3600ll * h + 60 * m + sec;
    myq.push(now);
  }
  while (!myq.empty()) {
    node now = myq.top();
    myq.pop();
    if (cnt == m) fnd = 1;
    if (now.in) {
      if (cnt == m) {
        fnd = 1;
        fans[now.id] = ans;
        out[ans] = now.time + t - 1;
        node next = {ans, now.time + t - 1, 0};
        myq.push(next);
      } else {
        ans++;
        fans[now.id] = ans;
        cnt++;
        out[ans] = now.time + t - 1;
        node next = {ans, now.time + t - 1, 0};
        myq.push(next);
      }
    } else {
      if (out[now.id] == now.time) {
        cnt--;
        out[now.id] = -1;
      }
    }
  }
  if (!fnd)
    cout << "No solution\n";
  else {
    cout << ans << endl;
    for (int i = 0; i < n; ++i) cout << fans[i] << endl;
  }
  return 0;
}
