#include <bits/stdc++.h>
using namespace ::std;
int main() {
  int N, M, T;
  cin >> N >> M >> T;
  vector<vector<int> > A(86400);
  for (int i = 0; i < N; i++) {
    string str;
    cin >> str;
    int x = 3600 * (10 * (str[0] - '0') + str[1] - '0') +
            60 * (10 * (str[3] - '0') + str[4] - '0') +
            (10 * (str[6] - '0') + str[7] - '0');
    A[x].push_back(i);
  }
  vector<int> id(N, -1);
  int cnt = 0;
  int mx = 0;
  map<int, int> mp;
  int last = -1;
  for (int i = 0; i < 86400; i++) {
    if (i >= T) {
      for (int j = 0; j < A[i - T].size(); j++) {
        int x = A[i - T][j];
        mp[id[x]]--;
        if (mp[id[x]] == 0) cnt--;
      }
    }
    for (int j = 0; j < A[i].size(); j++) {
      int x = A[i][j];
      if (cnt < M) {
        last++;
        cnt++;
        mx = max(mx, cnt);
      }
      id[x] = last;
      mp[last]++;
    }
  }
  if (mx != M) {
    std::cout << "No solution" << std::endl;
    return 0;
  }
  std::cout << (1 + last) << std::endl;
  for (int i = 0; i < N; i++) std::cout << (1 + id[i]) << std::endl;
  return 0;
}
