#include <bits/stdc++.h>
using namespace std;
int n, m, t, i, j, ans, a[20005], id[20005];
deque<pair<int, int> > b;
int main() {
  scanf("%d%d%d", &n, &m, &t);
  for (i = 0; i < n; i++) {
    int x, y, z;
    scanf("%d:%d:%d", &x, &y, &z);
    a[i] = x * 60 * 60 + y * 60 + z;
  }
  bool flag = 0;
  int ans = 0;
  for (i = 0; i < n; i++) {
    while (b.size() && b.front().first < a[i]) b.pop_front();
    if (b.size() == m) {
      id[i] = b.back().second;
      b.pop_back();
      b.push_back({a[i] + t - 1, id[i]});
    } else {
      b.push_back({a[i] + t - 1, ++ans});
      id[i] = ans;
      if (b.size() == m) flag = 1;
    }
  }
  if (!flag) return 0 * printf("No solution\n");
  printf("%d\n", ans);
  for (i = 0; i < n; i++) printf("%d\n", id[i]);
}
