#include <bits/stdc++.h>
using namespace std;
int n, m, t;
int q[86407];
vector<int> ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> t;
  int a, b, c;
  int nou = 0, cid = 1, last = 1;
  int tm, tb = 0, mx = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d:%d:%d", &a, &b, &c);
    int h = a * 3600 + b * 60 + c;
    for (int j = tb; j <= h; j++) nou += q[j];
    if (nou < 0 || nou > m) {
      cout << "No solution\n";
      return 0;
    }
    if (nou + 1 <= m) {
      nou++;
      q[h + t]--;
      ans.push_back(cid++);
      last = cid - 1;
      tm = h;
    } else {
      if (h >= tm + t) {
        cout << "No solution\n";
        return 0;
      }
      ans.push_back(last);
      q[tm + t]++;
      q[h + t]--;
      tm = h;
    }
    tb = h + 1;
    mx = max(nou, mx);
  }
  if (mx < m) {
    cout << "No solution\n";
    return 0;
  }
  cout << cid - 1 << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
  return 0;
}
