#include <bits/stdc++.h>
using namespace std;
int q[3000000], l, r, tot, cnt, n, m, t, flag, last;
int main() {
  cin >> n >> m >> t;
  vector<int> res;
  for (int i = 0; i < n; i++) {
    int hr, mn, second, x;
    scanf("%d:%d:%d", &hr, &mn, &second);
    x = hr * 3600 + mn * 60 + second;
    while (l < r && q[l] + t <= x) l++;
    if (r - l == m) {
      q[r - 1] = x;
      res.push_back(last);
    } else {
      q[r++] = x;
      last = ++tot;
      res.push_back(last);
    }
    if (r - l == m) {
      flag = 1;
    }
  }
  if (flag) {
    cout << tot << endl;
    for (auto x : res) cout << x << endl;
  } else
    cout << "No solution" << endl;
  return 0;
}
