#include <bits/stdc++.h>
using namespace std;
enum { REMOVE, ADD };
int n, M, T;
vector<vector<int>> adj;
vector<int> col;
void dfs(int v, int cc) {
  col[v] = cc;
  for (int u : adj[v])
    if (col[u] == 0) dfs(u, cc);
}
int main() {
  scanf("%d %d %d", &n, &M, &T);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    int h, m, s;
    scanf("%d:%d:%d", &h, &m, &s);
    a[i] = h * 60 * 60 + m * 60 + s;
  }
  vector<tuple<int, int, int>> ev;
  for (int i = 0; i < n; ++i) {
    ev.emplace_back(a[i], ADD, i);
    ev.emplace_back(a[i] + T, REMOVE, i);
  }
  sort(ev.begin(), ev.end());
  bool imp = true;
  adj = vector<vector<int>>(n);
  vector<bool> rem(n);
  int cur = 0;
  priority_queue<pair<int, int>> q;
  for (auto e : ev) {
    int t, tp, i;
    tie(t, tp, i) = e;
    if (tp == REMOVE) {
      if (!rem[i]) {
        cur -= 1;
        rem[i] = true;
      }
    } else {
      cur += 1;
      if (cur == M) {
        imp = false;
      }
      if (cur > M) {
        while (!q.empty() && rem[q.top().second]) q.pop();
        assert(!q.empty());
        int j = q.top().second;
        q.pop();
        rem[j] = true;
        cur -= 1;
        adj[i].push_back(j);
        adj[j].push_back(i);
      }
      q.emplace(t, i);
    }
  }
  if (imp) {
    cout << "No solution" << endl;
    return 0;
  }
  col = vector<int>(n);
  int cc = 0;
  for (int i = 0; i < n; ++i)
    if (col[i] == 0) dfs(i, ++cc);
  cout << cc << "\n";
  for (int i = 0; i < n; ++i) cout << col[i] << "\n";
  return 0;
}
