#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, M, T;
  cin >> n >> M >> T;
  vector<int> query_time;
  for (int i = 0; i < n; ++i) {
    int h, m, s;
    char c;
    cin >> h >> c >> m >> c >> s;
    query_time.push_back(h * 60 * 60 + m * 60 + s);
  }
  int id_cur = 1;
  int online_begin = 0;
  int online_count = 0;
  int online_max = 0;
  vector<int> id;
  for (int i = 0; i < n; ++i) {
    while (online_begin < query_time.size() &&
           query_time[online_begin] + (T - 1) < query_time[i]) {
      if (id[online_begin] != id[online_begin + 1]) {
        --online_count;
      }
      ++online_begin;
    }
    if (online_count + 1 <= M) {
      id.push_back(id_cur++);
      ++online_count;
      if (online_count > online_max) {
        online_max = online_count;
      }
    } else {
      id.push_back(id[i - 1]);
    }
  };
  if (online_max < M) {
    cout << "No solution" << endl;
  } else {
    cout << id_cur - 1 << endl;
    for (int i = 0; i < n; ++i) {
      cout << id[i] << endl;
    }
  }
  return 0;
}
