#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:36777216")
using namespace std;
const long long int inf = 100000000000000000LL;
struct Time {
  int open;
  int t;
  int i;
  int ans;
  bool operator<(const Time& o) const {
    if (t != o.t) return t < o.t;
    return open < o.open;
  }
};
struct mycmp {
  bool operator()(const Time& a, const Time& b) const {
    if (a.open != b.open) {
      return a.open < b.open;
    }
    return a.i < b.i;
  }
};
int curr[30000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  srand(23);
  int n, m, t;
  cin >> n >> m >> t;
  vector<Time> arr(n * 2);
  for (int i = 0; i < n; ++i) {
    int a, b, c;
    char q;
    cin >> a >> q >> b >> q >> c;
    arr[i].t = a * 60 * 60 + b * 60 + c;
    arr[i].i = i;
    arr[i].open = 1;
    arr[n + i].t = arr[i].t + t;
    arr[n + i].open = 0;
  }
  vector<int> ans(n);
  bool dsd = 0;
  sort(arr.begin(), arr.end());
  int index = 0;
  int c = 0;
  int live = 1;
  for (int i = 0; i < n * 2; ++i) {
    if (c == m) dsd = 1;
    if (arr[i].open == 1) {
      if (c < m) {
        index++;
        ans[arr[i].i] = index;
        curr[index]++;
        ++c;
      } else {
        curr[index]++;
        ans[arr[i].i] = index;
      }
    } else {
      curr[live]--;
      if (curr[live] == 0) {
        --c;
        ++live;
      }
    }
  }
  if (index < m || !dsd) {
    cout << "No solution";
    return 0;
  }
  cout << index << "\n";
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << "\n";
  }
  return 0;
}
