#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000000;
const int size = 86400;
vector<int> start[size];
int finish[size];
vector<int> ans;
int main() {
  for (int i = 0; i < size; i++) finish[i] = 0;
  int n, m, t;
  cin >> n >> m >> t;
  ans.resize(n);
  for (int i = 0; i < n; i++) {
    int x, y, z;
    scanf("%d:%d:%d", &x, &y, &z);
    x = (x * 60 + y) * 60 + z;
    start[x].push_back(i);
    finish[x + t - 1]++;
  }
  deque<int> a;
  int count = 0;
  int index = 0;
  int d = 0;
  bool was = false;
  for (int i = 0; i < size; i++) {
    for (int j = 0; j < start[i].size(); j++) {
      if (d < m) {
        ans[start[i][j]] = index++;
        count++;
        d++;
      } else {
        was = true;
        ans[start[i][j]] = ans[a[a.size() - 1]];
      }
      a.push_back(start[i][j]);
    }
    if (d == m) was = true;
    for (int j = 0; j < finish[i]; j++) {
      if (a.size() == 1 || (a.size() > 1 && ans[a[0]] != ans[a[1]])) d--;
      a.pop_front();
    }
  }
  if (!was) {
    cout << "No solution\n";
    return 0;
  }
  cout << count << endl;
  index = 1;
  int last = 0;
  for (int i = 0; i < n; i++) {
    if (ans[i] == last)
      printf("%d\n", index);
    else {
      last = ans[i];
      index++;
      printf("%d\n", index);
    }
  }
  return 0;
}
