#include <bits/stdc++.h>
using namespace std;
long long gcd(long long b, long long s) { return (s != 0) ? gcd(s, b % s) : b; }
long long Pow(long long a, long long b, long long c) {
  if (b == 0)
    return 1 % c;
  else if (b == 1)
    return a % c;
  else {
    long long A = Pow(a, b / 2, c);
    A = (A * A) % c;
    if (b & 1) A = (A * a) % c;
    return A;
  }
}
const long long INF = 1e9 + 7;
const long long INF9 = 1e9 + 9;
int p[20005];
vector<pair<int, int> > a;
int max_dep(int n) {
  vector<pair<int, int> > b;
  for (int i = 0; i < n; i++) {
    b.push_back(pair<int, int>(a[i].first, -1));
    b.push_back(pair<int, int>(a[i].second, 1));
  }
  sort(b.begin(), b.end());
  int dep = 0, cur_dep = 0;
  for (int i = 0; i < b.size(); i++) {
    cur_dep -= b[i].second;
    dep = max(dep, cur_dep);
  }
  return dep;
}
int Find(int x) { return (p[x] != x) ? (p[x] = Find(p[x])) : x; }
void Union(int u, int v) { p[Find(u)] = Find(v); }
map<int, int> cx;
void get(int n, int m) {
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) p[i] = i;
  set<int> s;
  set<int>::iterator it;
  for (int i = 0; i < n; i++) {
    vector<int> c;
    for (it = s.begin(); it != s.end(); it++) {
      if (a[(*it)].second < a[i].first) {
        c.push_back(*it);
      } else
        break;
    }
    for (int i = 0; i < c.size(); i++) s.erase(c[i]);
    int si = s.size();
    if (si + 1 <= m) {
      s.insert(i);
    } else {
      it = s.end();
      it--;
      Union((*it), i);
      s.erase(it);
      s.insert(i);
    }
  }
  vector<int> re;
  set<int> cc;
  for (int i = 0; i < n; i++) {
    int id = Find(i) + 1;
    re.push_back(id);
    cc.insert(id);
  }
  printf("%d\n", cc.size());
  int id = 0;
  for (it = cc.begin(); it != cc.end(); it++) cx[*it] = ++id;
  for (int i = 0; i < re.size(); i++) printf("%d\n", cx[re[i]]);
}
int main() {
  int n, m, t;
  scanf("%d %d %d", &n, &m, &t);
  for (int i = 0; i < n; i++) {
    int h, m, s;
    scanf("%d:%d:%d", &h, &m, &s);
    int cur = h * 3600 + m * 60 + s;
    a.push_back(pair<int, int>(cur, cur + t - 1));
  }
  int dep = max_dep(n);
  if (dep < m) {
    puts("No solution");
    return 0;
  }
  get(n, m);
}
