#include <bits/stdc++.h>
using namespace std;
const int N = 20005;
const int Period = 24 * 60 * 60 + 100;
set<pair<int, int>, greater<pair<int, int> > > activeSet;
set<pair<int, int>, greater<pair<int, int> > >::iterator it;
int input[N], a[N];
int start[Period];
vector<int> ans[Period];
int main() {
  int n, M, T, h, m, s, userID = 1;
  bool ok = false;
  scanf("%d %d %d", &n, &M, &T);
  for (int i = 0; i < n; ++i) {
    scanf("%d:%d:%d", &h, &m, &s);
    input[i] = (h * 60 + m) * 60 + s;
    a[i] = input[i];
    start[a[i]]++;
  }
  sort(a, a + n);
  for (int i = 0; i < Period; ++i) {
    while (1) {
      if (activeSet.size() == 0) break;
      it = activeSet.end();
      it--;
      if (it->first < i)
        activeSet.erase(it);
      else
        break;
    }
    while (start[i] && activeSet.size() < M) {
      start[i]--;
      activeSet.insert(make_pair(i + T - 1, userID++));
      ans[i].push_back(userID - 1);
    }
    while (start[i]--) {
      it = activeSet.begin();
      int idx = it->second;
      int val = i + T - 1;
      ans[i].push_back(idx);
      activeSet.erase(it);
      activeSet.insert(make_pair(val, idx));
    }
    if (activeSet.size() == M) {
      ok = true;
    }
  }
  if (!ok) {
    printf("No solution");
    return 0;
  }
  printf("%d\n", userID - 1);
  for (int i = 0; i < n; ++i) {
    printf("%d\n", ans[input[i]].back());
    ans[input[i]].pop_back();
  }
  return 0;
}
