#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, m, t;
  bool was_max = false;
  cin >> n >> m >> t;
  char dots;
  int h, d, s;
  vector<int> times;
  while (cin >> h >> dots >> d >> dots >> s) {
    d += h * 60;
    s += d * 60;
    times.push_back(s);
  }
  int cur_pos = 0;
  int counter = 0;
  int left = 0;
  int right = 0;
  int border = 0;
  vector<int> ans;
  while (left <= right) {
    while (right < times.size() && times[right] <= times[left] + t - 1) {
      right++;
    }
    right--;
    if (counter < m) {
      cur_pos++;
      counter++;
    }
    if (right - left + 1 >= m) {
      was_max = true;
    }
    ans.push_back(cur_pos);
    left++;
    if (times[left] > times[border] + t - 1) {
      int last = border;
      int temp_cnt = 0;
      while (border < n && times[left] > times[border] + t - 1) {
        border++;
      }
      for (int i = last + 1; i <= border; i++) {
        if (ans[i] != ans[i - 1]) temp_cnt++;
      }
      counter -= temp_cnt;
    }
    if (left > right && right < n - 1) {
      right++;
    }
  }
  if (!was_max) {
    cout << "No solution";
    return 0;
  }
  cout << cur_pos << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
