#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
using vi = vector<int>;
using vld = vector<ld>;
using vll = vector<ll>;
int n, M, T;
vector<int> times;
struct guy {
  int last;
  int id;
  bool operator<(guy o) const { return last < o.last; }
};
int ans[200005];
void solve() {
  if (n < M) {
    cout << "No solution" << endl;
    return;
  }
  multiset<guy> s;
  set<int> notused;
  for (int i = 1; i < n + 1; ++i) {
    notused.insert(i);
  }
  bool reachm = false;
  int R = 0;
  for (int i = 0; i < n; ++i) {
    while (!s.empty() && s.begin()->last + T <= times[i]) {
      s.erase(s.begin());
    }
    if (s.size() < M) {
      int id = *notused.begin();
      s.insert(guy{times[i], *notused.begin()});
      notused.erase(notused.begin());
      ans[i] = id;
      R = max(R, id);
    } else {
      auto itr = --s.end();
      guy g = *itr;
      s.erase(itr);
      g.last = times[i];
      s.insert(g);
      ans[i] = g.id;
    }
    if (s.size() == M) {
      reachm = true;
    }
  }
  if (!reachm) {
    cout << "No solution" << endl;
    return;
  }
  cout << R << endl;
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << endl;
  }
}
void read() {
  scanf("%d%d%d", &n, &M, &T);
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    int time = stoi(s.substr(0, 2)) * 3600 + stoi(s.substr(3, 2)) * 60 +
               stoi(s.substr(6, 2));
    times.push_back(time);
  }
}
int main() {
  read();
  solve();
}
