#include <bits/stdc++.h>
using namespace std;
int tree[262144][4], L[100005], n, m, p[100005], FLAG, i, M, T, G;
char s[10005];
void Update(int x) {
  tree[x * 2][2] += tree[x][3];
  tree[x * 2 + 1][2] += tree[x][3];
  tree[x * 2][3] += tree[x][3];
  tree[x * 2 + 1][3] += tree[x][3];
  tree[x][3] = 0;
}
int cmp(int i, int j) { return i < j; }
void work(int root, int l, int r, int t) {
  if (l == tree[root][0] && r == tree[root][1]) {
    tree[root][2] += t;
    tree[root][3] += t;
    return;
  }
  Update(root);
  int mid = (tree[root][0] + tree[root][1]) / 2;
  if (l <= mid) work(root * 2, l, min(mid, r), t);
  if (r > mid) work(root * 2 + 1, max(mid + 1, l), r, t);
  tree[root][2] = max(tree[root * 2][2], tree[root * 2 + 1][2]);
}
int main() {
  for (i = 131072; i < 262144; i++) tree[i][0] = tree[i][1] = i;
  for (i = 131071; i >= 1; i--)
    tree[i][0] = tree[i + i][0], tree[i][1] = tree[i + i + 1][1];
  scanf("%d%d%d", &n, &M, &T);
  for (i = 1; i <= n; i++) {
    scanf("%s", s);
    L[i] = ((s[0] - '0') * 10 + s[1] - '0') * 3600 +
           ((s[3] - '0') * 10 + s[4] - '0') * 60 + (s[6] - '0') * 10 + s[7] -
           '0' + 1;
  }
  sort(L + 1, L + n + 1, cmp);
  for (i = 1; i <= n; i++) {
    work(1, 131071 + L[i], 131070 + L[i] + T, 1);
    G = tree[1][2];
    if (G == M) FLAG = 1;
    if (G > M) {
      work(1, 131071 + L[i], 131070 + L[i - 1] + T, -1);
      p[i] = p[i - 1];
    } else
      p[i] = p[i - 1] + 1;
  }
  if (!FLAG) {
    puts("No solution");
    return 0;
  }
  cout << p[n] << endl;
  for (i = 1; i <= n; i++) printf("%d\n", p[i]);
  return 0;
}
