#include <bits/stdc++.h>
using namespace std;
char _temp;
bool _flag;
inline void getint(int &_num) {
  _num = _flag = 0;
  while (1) {
    _temp = getchar();
    if (_temp >= 48 && _temp <= 57) {
      _num = _num * 10 + _temp - 48;
      _flag = 1;
    } else if (_flag)
      return;
  }
}
set<pair<int, int> > s;
int ed[100005], rel[100005];
int main() {
  int n, m, T, now, a, nr, ans, mx = 0, i;
  cin >> n >> m >> T;
  nr = ans = 0;
  for (i = 1; i <= n; i++) {
    now = 0;
    getint(a);
    now += a * 3600;
    getint(a);
    now += a * 60;
    getint(a);
    now += a;
    while (!s.empty() && (*s.begin()).first <= now) {
      s.erase(s.begin());
      nr--;
    }
    if (nr < m) {
      ans++;
      rel[i] = ans;
      ed[rel[i]] = now + T;
      s.insert(make_pair(ed[rel[i]], rel[i]));
      nr++;
    } else {
      rel[i] = (*s.rbegin()).second;
      s.erase(*s.rbegin());
      ed[rel[i]] = now + T;
      s.insert(make_pair(ed[rel[i]], rel[i]));
    }
    mx = max(mx, nr);
  }
  if (mx < m)
    printf("No solution\n");
  else {
    cout << ans << endl;
    for (i = 1; i <= n; i++) printf("%d\n", rel[i]);
  }
  return 0;
}
