#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, t;
  cin >> n >> m >> t;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int x = (s[0] - '0') * 10 + (s[1] - '0');
    x *= 60;
    x += (s[3] - '0') * 10 + (s[4] - '0');
    x *= 60;
    x += (s[6] - '0') * 10 + (s[7] - '0');
    a[i] = x;
  }
  int r = 1;
  bool ok = false;
  if (m > n) {
    cout << "No solution" << endl;
    return 0;
  }
  vector<int> ans(n, -1);
  int j = 0;
  for (int i = 0; i < n; i++) {
    if (ans[i] == -1) {
      if (i == 0)
        ans[i] = 1;
      else
        ans[i] = ans[i - 1] + 1;
    }
    while (j < a.size() && a[j] - a[i] < t) {
      if (ans[j] == -1) {
        ans[j] = ans[j - 1];
        if (ans[j] - ans[i] + 1 < m) ans[j]++;
      }
      j++;
    }
    if (ans[j - 1] - ans[i] + 1 == m) ok = true;
  }
  if (!ok) {
    cout << "No solution" << endl;
    return 0;
  }
  cout << ans[n - 1] << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
}
