#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, t, timer = 0;
  scanf("%d%d%d", &n, &m, &t);
  deque<int> q;
  vector<int> col(n);
  char isOk = false;
  for (int i = 0, j = 0; i < n; i++) {
    int x, y, z, start;
    scanf("\n%d:%d:%d", &x, &y, &z);
    start = x * 3600 + y * 60 + z;
    while (!q.empty() && q.front() <= start) {
      j--;
      q.pop_front();
    }
    if (j < m) {
      j++;
      q.push_back(start + t);
      timer++;
    } else {
      q.back() = start + t;
    }
    if (j == m) {
      isOk = true;
    }
    col[i] = timer;
  }
  if (!isOk) {
    printf("No solution");
    return 0;
  }
  printf("%d\n", timer);
  for (int i : col) {
    printf("%d\n", i);
  }
  return 0;
}
