#include <bits/stdc++.h>
using namespace std;
const long long inf = 2e18 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
const double PI = 2 * acos(0.0);
int ans[1000000];
int main() {
  int n, m, t;
  scanf("%d%d%d", &n, &m, &t);
  list<int> MagicPony;
  bool ok = false;
  int kol = 0, ost = 0;
  for (int i = 0; i < n; i++) {
    int hh, mm, ss;
    scanf("%d:%d:%d", &hh, &mm, &ss);
    int tim = hh * 3600 + mm * 60 + ss;
    while (kol > 0 && MagicPony.front() <= tim) {
      kol--;
      MagicPony.pop_front();
    }
    if (kol < m) {
      ost++;
      kol++;
      MagicPony.push_back(tim + t);
    } else {
      MagicPony.back() = tim + t;
    }
    if (kol == m) ok = true;
    ans[i] = ost;
  }
  if (!ok) {
    cout << "No solution" << endl;
    return 0;
  }
  cout << ost << endl;
  for (int i = 0; i < n; i++) cout << ans[i] << endl;
}
