#include <bits/stdc++.h>
using namespace std;
long long int st[4 * 86500];
long long int lz[4 * 86500];
void update(long long int node, long long int ss, long long int sf,
            long long int qs, long long int qe, long long int val) {
  if (lz[node]) {
    st[node] += (sf - ss + 1) * lz[node];
    if (ss != sf) {
      lz[2 * node] += lz[node];
      lz[2 * node + 1] += lz[node];
    }
    lz[node] = 0;
  }
  if (qs > sf || qe < ss || sf < ss) return;
  if (qs <= ss && qe >= sf) {
    st[node] += (sf - ss + 1) * val;
    if (ss != sf) {
      lz[2 * node] += val;
      lz[2 * node + 1] += val;
    }
    return;
  }
  long long int mid = (ss + sf) / 2;
  update(2 * node, ss, mid, qs, qe, val);
  update(2 * node + 1, mid + 1, sf, qs, qe, val);
  st[node] = st[2 * node] + st[2 * node + 1];
}
long long int query(long long int node, long long int ss, long long int sf,
                    long long int qs, long long int qe) {
  if (lz[node]) {
    st[node] += (sf - ss + 1) * lz[node];
    if (ss != sf) {
      lz[2 * node] += lz[node];
      lz[2 * node + 1] += lz[node];
    }
    lz[node] = 0;
  }
  if (qs > sf || qe < ss || sf < ss) return 0;
  if (qs <= ss && qe >= sf) return st[node];
  long long int mid = (ss + sf) / 2;
  return query(2 * node, ss, mid, qs, qe) +
         query(2 * node + 1, mid + 1, sf, qs, qe);
}
int main() {
  long long int T = 1;
  for (long long int qq = 1; qq <= T; qq++) {
    long long int n, M, t;
    cin >> n >> M >> t;
    vector<long long int> ans;
    long long int prev = 0;
    long long int p_pos = 0;
    long long int mx = 0;
    for (int i = 0; i < n; i++) {
      int h, m, s;
      scanf("%d:%d:%d", &h, &m, &s);
      h *= 60;
      m += h;
      m *= 60;
      s += m;
      long long int x = query(1, 0, 86500 - 1, s, s);
      if (x < M) {
        prev++;
        mx = max(mx, x + 1);
        update(1, 0, 86500 - 1, s, s + t - 1, 1);
      } else if (p_pos != s)
        update(1, 0, 86500 - 1, p_pos + t, s + t - 1, 1);
      ans.push_back(prev);
      p_pos = s;
    }
    if (mx < M) {
      cout << "No solution" << endl;
      return 0;
    }
    cout << prev << endl;
    for (auto x : ans) {
      printf("%lld\n", x);
    }
  }
  return 0;
}
