#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  os << "[";
  for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
    if (it != t.begin()) os << ",";
    os << *it;
  }
  os << "]";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &t) {
  os << "{";
  for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
    if (it != t.begin()) os << ",";
    os << *it;
  }
  os << "}";
  return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &t) {
  return os << "(" << t.first << "," << t.second << ")";
}
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first - t.first, s.second - t.second);
}
const int INF = 1 << 28;
const double EPS = 1e-8;
const int MOD = 1000000007;
int n, m, t;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  scanf("%d%d%d", &n, &m, &t);
  deque<pair<int, int> > ends;
  int ans = 0, accept = 0;
  vector<int> idxs(n);
  for (int i = 0; i < (int)(n); i++) {
    int h, mm, s, x;
    scanf("%d:%d:%d", &h, &mm, &s);
    x = h * 3600 + mm * 60 + s;
    while (!ends.empty() && ends.front().first <= x) {
      idxs[ends.front().second] = 1;
      ans++;
      ends.pop_front();
    }
    ends.emplace_back(x + t, i);
    if (ends.size() == m) accept = 1;
    while (ends.size() > m) {
      idxs[ends.back().second] = 0;
      ends.pop_back();
      ends.back().first = x + t;
    }
  }
  while (!ends.empty()) {
    idxs[ends.back().second] = 1;
    ans++;
    ends.pop_back();
  }
  if (!accept) {
    puts("No solution");
    return 0;
  }
  int sum = 0;
  printf("%d\n", ans);
  for (int i = 0; i < (int)(n); i++) printf("%d\n", sum += idxs[i]);
  return 0;
}
