#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const double eps = 1e-7;
const int maxn = 21000;
const int maxt = 86500;
int id[maxn];
int s[maxt + 1];
int t[maxn];
int moved[maxn];
void add(int x, int val) {
  while (x <= maxt) {
    s[x] += val;
    x = (x << 1) - (x & (x - 1));
  }
}
int get(int x) {
  int sum = 0;
  while (x) {
    sum += s[x];
    x = x & (x - 1);
  }
  return sum;
}
int main() {
  int n, M, T;
  scanf("%d%d%d\n", &n, &M, &T);
  int pos = 0, ids = 0, mx = 0;
  for (int i = 0; i < n; ++i) {
    int hh, mm, ss;
    scanf("%d:%d:%d\n", &hh, &mm, &ss);
    int time = hh * 60 * 60 + mm * 60 + ss + 1;
    t[i] = time;
    while (t[pos] + T - 1 < time) {
      if (!moved[pos]) add(t[pos] + T - 1, -1);
      ++pos;
    }
    int cur = get(time + T);
    if (cur < M) {
      ++ids;
      id[i] = ids;
      add(time + T - 1, 1);
      mx = max(cur + 1, mx);
    } else {
      assert(pos < i);
      add(t[i - 1] + T - 1, -1);
      id[i] = id[i - 1];
      add(time + T - 1, 1);
      moved[i - 1] = true;
    }
  }
  if (mx != M) {
    puts("No solution");
    return 0;
  }
  printf("%d\n", ids);
  for (int i = 0; i < n; ++i) {
    printf("%d\n", id[i]);
  }
  return 0;
}
