#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 2 * MOD;
int main() {
  ios_base::sync_with_stdio(0);
  int n, m, t;
  cin >> n >> m >> t;
  bool was = false;
  vector<int> id(n);
  int max_id = 0;
  queue<int> q;
  int size = 0;
  for (int i = 0; i < n; ++i) {
    int hh, mm, ss;
    char ch;
    cin >> hh >> ch >> mm >> ch >> ss;
    int time = hh * 3600 + mm * 60 + ss;
    while (!q.empty() && q.front() < time) {
      --size;
      q.pop();
    }
    if (size < m) {
      ++max_id;
      ++size;
      q.push(time + t - 1);
    } else {
      q.back() = time + t - 1;
    }
    id[i] = max_id;
    if (size == m) {
      was = true;
    }
  }
  if (!was) {
    cout << "No solution";
  } else {
    cout << max_id << endl;
    for (int i = 0; i < n; ++i) {
      cout << id[i] << endl;
    }
  }
  return 0;
}
