#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const signed long long int LINF = LLONG_MAX;
const double EPS = 1e-9;
const int MOD = 1000000007;
const int MAXN = 100001;
const int ALPH = 26;
const int DALPH = 52;
int readTime() {
  int h, m, s;
  scanf("%d:%d:%d", &h, &m, &s);
  return s + (m + h * 60) * 60;
}
int n, M, T;
vector<int> beginTime;
vector<int> color;
vector<int> colorCnt;
int colorNum;
int main() {
  scanf("%d %d %d", &n, &M, &T);
  beginTime.resize(n);
  for (int i = 0; i < n; ++i) {
    beginTime[i] = readTime();
  }
  int currColor = 1;
  color.resize(n);
  bool ans = false;
  colorCnt.resize(n + 1);
  colorNum = 0;
  int l = 0, r = 0;
  while (r < n) {
    while (l < r && beginTime[l] + T - 1 < beginTime[r]) {
      if (--colorCnt[color[l]] == 0) {
        --colorNum;
      }
      ++l;
    }
    if (colorNum < M) {
      color[r] = currColor++;
    } else {
      color[r] = color[r - 1];
    }
    if (++colorCnt[color[r]] == 1) {
      ++colorNum;
    }
    if (colorNum == M) {
      ans = true;
    }
    ++r;
  }
  if (!ans) {
    puts("No solution");
    return 0;
  }
  printf("%d\n", currColor - 1);
  for (int i = 0; i < n; ++i) {
    printf("%d\n", color[i]);
  }
}
