#include <bits/stdc++.h>
using namespace std;
int n, M, T;
int t[20000];
int who[20000];
int k = 1;
int mx = 0;
deque<pair<int, int> > q;
int gn(char x) { return x - (int)('0'); }
int read() {
  char h1, h2, m1, m2, s1, s2;
  scanf("%c%c:%c%c:%c%c\n", &h1, &h2, &m1, &m2, &s1, &s2);
  return gn(h1) * 36000 + gn(h2) * 3600 + gn(m1) * 600 + gn(m2) * 60 +
         gn(s1) * 10 + gn(s2);
}
int main() {
  scanf("%d %d %d\n", &n, &M, &T);
  for (int i = 0; i < n; i++) {
    t[i] = read();
  }
  mx = 0;
  for (int i = 0; i < n; i++) {
    int curr = t[i];
    while (q.empty() == false) {
      if (q.front().first + T <= curr) {
        q.pop_front();
      } else {
        break;
      }
    }
    if (q.size() < M) {
      who[i] = k++;
      q.push_back(make_pair(curr, k - 1));
    } else {
      mx = 1;
      who[i] = q.back().second;
      q.pop_back();
      q.push_back(make_pair(curr, who[i]));
    }
  }
  if (mx || q.size() == M) {
    printf("%d\n", k - 1);
    for (int i = 0; i < n; i++) {
      printf("%d\n", who[i]);
    }
  } else {
    printf("No solution");
  }
  return 0;
}
