#include <bits/stdc++.h>
using namespace std;
int n, m, t;
int a[21000];
int b[1000000];
deque<pair<int, int> > w;
string s;
int ans[21000];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> t;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    a[i] = ((s[0] - '0') * 10 + (s[1] - '0')) * 60 * 60 +
           ((s[3] - '0') * 10 + (s[4] - '0')) * 60 +
           ((s[6] - '0') * 10 + (s[7] - '0'));
  }
  bool was = false;
  int top = 1;
  for (int i = 0; i < n; ++i) {
    if (i) {
      while (w.size() && w.front().second <= a[i]) w.pop_front();
    }
    if (w.size() < m)
      b[a[i] + t]++, w.push_back(make_pair(i, a[i] + t)), ans[i] = top++;
    else {
      pair<int, int> wb = w.back();
      w.pop_back();
      int v = wb.first;
      int p = wb.second;
      b[p]--;
      b[a[i] + t]++;
      wb.second = a[i] + t;
      w.push_back(wb);
      ans[i] = ans[v];
    }
    if (w.size() == m) was = true;
  }
  if (!was)
    printf("No solution");
  else {
    printf("%d\n", top - 1);
    for (int i = 0; i < n; ++i) printf("%d\n", ans[i]);
  }
}
