#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:256000000")
const int N = 100000;
int n, m, T;
priority_queue<pair<int, int> > qq;
int ans[N];
int was[N];
int qqq = 0;
int main() {
  scanf("%d %d %d\n", &n, &m, &T);
  for (int i = 0; i < n; ++i) {
    int h, t, s;
    scanf("%d:%d:%d\n", &h, &t, &s);
    s += t * 60 + h * 3600;
    qq.push(pair<int, int>(-s, -1));
  }
  int k = 0;
  int r = 0, id = 1;
  while (!qq.empty()) {
    pair<int, int> t = qq.top();
    qq.pop();
    if (t.second == -1) {
      if (r == m) {
        ans[k] = id - 1;
        qq.push(pair<int, int>(t.first - T, id - 1));
        was[id - 1]++;
      } else {
        r++;
        qq.push(pair<int, int>(t.first - T, id));
        ans[k] = id;
        was[id]++;
        id++;
      }
      if (r == m) qqq = 1;
      k++;
    } else {
      was[t.second]--;
      if (!was[t.second]) r--;
    }
  }
  if (!qqq) {
    cout << "No solution";
    return 0;
  }
  printf("%d\n", id - 1);
  for (int i = 0; i < n; ++i) printf("%d\n", ans[i]);
}
