#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m, t;
  scanf("%d%d%d", &n, &m, &t);
  vector<int> times(n);
  set<pair<int, int> > q;
  for (int i = 0; i < n; i++) {
    int x, y, z;
    scanf("%d:%d:%d", &x, &y, &z);
    times[i] = x * 3600 + y * 60 + z;
    q.insert({times[i], i});
  }
  set<pair<int, int>, greater<pair<int, int> > > online;
  int id = 0;
  vector<int> ans(n);
  bool ok = false;
  while (!q.empty()) {
    auto x = *q.begin();
    q.erase(q.begin());
    int val = x.first;
    int pos = x.second;
    if (pos >= 0) {
      if ((int)online.size() == m) {
        pair<int, int> fst = *online.begin();
        q.erase({fst.first, -fst.second - 1});
        online.erase(online.begin());
        online.insert({val + t, fst.second});
        q.insert({val + t, -1 - fst.second});
        ans[pos] = fst.second;
      } else {
        ans[pos] = id;
        q.insert({val + t, -id - 1});
        online.insert({val + t, id++});
      }
    } else {
      online.erase({val, -pos - 1});
    }
    if ((int)online.size() == m) ok = true;
  }
  if (!ok) {
    cout << "No solution\n";
  } else {
    printf("%d\n", id);
    for (int x : ans) printf("%d ", x + 1);
  }
}
int main() {
  solve();
  return 0;
}
