#include <bits/stdc++.h>
using namespace std;
template <typename C>
void MA(C& a, C b) {
  if (a < b) a = b;
}
template <typename C>
void MI(C& a, C b) {
  if (a > b) a = b;
}
int n, m, t;
int d[20010];
int get_time() {
  int a, b, c;
  scanf("%d:%d:%d", &a, &b, &c);
  return a * 3600 + b * 60 + c;
}
priority_queue<pair<int, int> > z;
int sum[20010];
vector<int> wyny;
int main() {
  scanf("%d%d", &n, &m);
  scanf("%d", &t);
  for (int i = 0; i < n; i++) {
    d[i] = get_time();
    z.push(make_pair(-d[i], -1));
  }
  int il = 0;
  int ost = 0;
  bool cz = 0;
  while (!z.empty()) {
    pair<int, int> ak = z.top();
    z.pop();
    if (ak.second == -1) {
      if (il != m) {
        ost++;
        il++;
        if (il == m) cz = 1;
      }
      wyny.push_back(ost);
      z.push(make_pair(ak.first - t, ost));
      sum[ost]++;
    } else {
      sum[ak.second]--;
      if (sum[ak.second] == 0) il--;
    }
  }
  if (!cz) {
    puts("No solution");
  } else {
    printf("%d\n", ost);
    for (int i = 0; i < n; i++) {
      printf("%d\n", wyny[i]);
    }
  }
}
