#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmin(T &t, const T &f) {
  if (t > f) t = f;
}
template <class T>
void chmax(T &t, const T &f) {
  if (t < f) t = f;
}
int tree[86410];
int read(int idx) {
  int sum = 0;
  while (idx > 0) {
    sum += tree[idx];
    idx -= (idx & -idx);
  }
  return sum;
}
void update(int idx, int val) {
  while (idx <= 86410) {
    tree[idx] += val;
    idx += (idx & -idx);
  }
}
int getTime(char a[100]) {
  int hour = 0, mini = 0, sec = 0, time;
  if (a[0] != '0') hour = (a[0] - '0') * (10);
  if (a[1] != '0') hour += (a[1] - '0');
  if (a[3] != '0') mini = (a[3] - '0') * 10;
  if (a[4] != '0') mini += (a[4] - '0');
  if (a[6] != '0') sec = (a[6] - '0') * 10;
  if (a[7] != '0') sec += (a[7] - '0');
  time += (hour * (60 * 60)) + (mini * (60)) + sec;
  return time + 1;
}
int main() {
  int n, m, t, prevId, prevTime = 0, id = 0, pos = 0;
  vector<int> ans;
  scanf("%d %d %d", &n, &m, &t);
  for (int i = 0; i < n; ++i) {
    char a[100];
    scanf("%s", a);
    int time = getTime(a);
    int num = read(time);
    if (num < m) {
      ans.push_back(++id);
      update(time, 1);
      update(min(86410, time + t), -1);
      prevTime = min(86410, time + t);
      prevId = id;
    } else {
      ans.push_back(id);
      pos = 1;
      update(prevTime, 1);
      update(min(86410, time + t), -1);
      prevTime = min(86410, time + t);
      prevId = id;
    }
  }
  if (!pos) {
    for (int i = 1; i < 86410; ++i) {
      int num = read(i);
      if (num >= m) pos = 1;
    }
  }
  if (pos) {
    printf("%d\n", id);
    for (int i = 0; i < ans.size(); ++i) printf("%d\n", ans[i]);
    return 0;
  }
  printf("No solution");
  return 0;
}
