#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-6;
int main() {
  { ; };
  int n, M, T;
  scanf("%d %d %d", &n, &M, &T);
  vector<int> times(n);
  for (int i = 0; i < n; i++) {
    int hh, mm, ss;
    scanf("%d:%d:%d", &hh, &mm, &ss);
    times[i] = hh * 3600 + mm * 60 + ss;
  }
  vector<int> ids(n);
  int R = 1;
  int nowId = 1;
  int lb = 0;
  for (int rb = 0; rb < n; rb++) {
    while (times[rb] >= times[lb] + T) lb++;
    int userCount = nowId - ids[lb];
    if (lb == rb || userCount < M)
      ids[rb] = nowId++;
    else
      ids[rb] = nowId - 1;
    R = max(R, nowId - ids[lb]);
  }
  if (R != M)
    puts("No solution");
  else {
    printf("%d\n", nowId - 1);
    for (int i = 0; i < n; i++) printf("%d\n", ids[i]);
  }
  return 0;
}
