#include <bits/stdc++.h>
using namespace std;
int a[int(1e5 + 5)], b[int(1e5 + 5)], C[int(1e5 + 5)], i, m, ans, k, l, j, q, x,
    n, ma, mi, t, rao, TT = 0, F;
string s;
char c;
vector<int> v, AN;
int main() {
  cin >> n >> m >> t;
  for (int i = 0; i < n; i++)
    cin >> k >> c >> l >> c >> q, v.push_back(k * 60 * 60 + l * 60 + q),
        a[k * 60 * 60 + l * 60 + q]++;
  k = 0;
  for (int i = 0; i < 24 * 60 * 60; i++) {
    k -= b[i];
    if (a[i] == 0) continue;
    int ls = i;
    for (int j = 0; j < a[i]; j++) {
      if (k < m) {
        k++;
        AN.push_back(++TT);
        C[TT] = i + t;
      } else {
        AN.push_back(TT);
        b[C[TT]]--;
        C[TT] = i + t;
      }
      b[i + t]++;
      if (k == m) {
        F = 1;
      }
    }
  }
  if (!F) {
    cout << "No solution";
    return 0;
  }
  cout << TT << endl;
  for (int i = 0; i < n; i++) cout << AN[i] << endl;
}
