#include <bits/stdc++.h>
using namespace std;
const int maxn = 20010;
string str;
int y[maxn];
int ans[maxn];
int tot;
map<int, int> mp;
int main() {
  int n, m, t;
  cin >> n >> m >> t;
  for (int i = 0; i < n; i++) {
    cin >> str;
    for (int j = 0; j < str.size(); j++)
      if (str[j] == ':') str[j] = ' ';
    stringstream ss(str);
    int tmp = 0, x = 0;
    while (ss >> tmp) x = x * 60 + tmp;
    y[i] = x;
  }
  tot = 0;
  int k = 0, id = 0;
  bool flag = false;
  for (int i = 0; i < n && k < n; i++) {
    while (y[k] < y[i] + t && k < n) {
      if (mp.size() < m)
        ans[tot++] = ++id;
      else
        ans[tot++] = id;
      mp[id]++;
      k++;
      if (mp.size() == m) flag = true;
    }
    mp[ans[i]]--;
    if (mp[ans[i]] == 0) mp.erase(ans[i]);
  }
  if (!flag)
    puts("No solution");
  else {
    printf("%d\n", ans[tot - 1]);
    for (int i = 0; i < tot; i++) printf("%d\n", ans[i]);
  }
  return 0;
}
