#include <bits/stdc++.h>
using namespace std;
struct info {
  long long prop, sum;
} tree[2000005 * 3];
void update(int node, int b, int e, int i, int j, long long x) {
  if (i > e || j < b) return;
  if (b >= i && e <= j) {
    tree[node].sum += ((e - b + 1) * x);
    tree[node].prop += x;
    return;
  }
  int Left = node * 2;
  int Right = (node * 2) + 1;
  int mid = (b + e) / 2;
  update(Left, b, mid, i, j, x);
  update(Right, mid + 1, e, i, j, x);
  tree[node].sum =
      tree[Left].sum + tree[Right].sum + (e - b + 1) * tree[node].prop;
}
int query(int node, int b, int e, int i, int j, int carry = 0) {
  if (i > e || j < b) return 0;
  if (b >= i and e <= j) return tree[node].sum + carry * (e - b + 1);
  int Left = node << 1;
  int Right = (node << 1) + 1;
  int mid = (b + e) >> 1;
  int p1 = query(Left, b, mid, i, j, carry + tree[node].prop);
  int p2 = query(Right, mid + 1, e, i, j, carry + tree[node].prop);
  return p1 + p2;
}
int main() {
  int n, m, t;
  cin >> n >> m >> t;
  int last = 0;
  vector<pair<int, int> > v;
  int poss = 0;
  while (n--) {
    int hh, mm, ss;
    scanf("%d:%d:%d", &hh, &mm, &ss);
    int time = hh * 3600 + mm * 60 + ss;
    int online = query(1, 0, 86399, time, time);
    if (online < m) {
      if (online == m - 1) poss = 1;
      v.push_back({++last, min(time + t - 1, 86399)});
      update(1, 0, 86399, time, min(time + t - 1, 86399), 1);
    } else {
      update(1, 0, 86399, v.back().second + 1, min(time + t - 1, 86399), 1);
      v.push_back({last, min(time + t - 1, 86399)});
    }
  }
  if (!poss) {
    cout << "No solution";
    return 0;
  }
  cout << last << endl;
  for (int i = 0; i < v.size(); i++) cout << v[i].first << endl;
}
