#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
bool MinPlace(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool MaxPlace(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename S, typename T>
ostream &operator<<(ostream &out, const pair<S, T> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  for (int i = 0; i < (int)v.size(); i++) {
    out << v[i];
    if (i != (int)v.size() - 1) out << ", ";
  }
  out << "]";
  return out;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m, T;
  cin >> n >> m >> T;
  vector<int> times;
  vector<pair<int, int>> events;
  for (int i = 0; i < n; i++) {
    int h, m, s, t = 0;
    char ch;
    cin >> h >> ch >> m >> ch >> s;
    t = ((h * 60 + m) * 60) + s;
    times.push_back(t);
    events.push_back(make_pair(t, i));
    events.push_back(make_pair(t + T, i));
  }
  sort(events.begin(), events.end());
  vector<int> identity(n, 0);
  unordered_set<int> open;
  deque<int> current;
  bool tight = false;
  for (int i = 0; i < events.size(); i++) {
    int t = events[i].first, index = events[i].second;
    if (open.count(index)) {
      if (current.front() == index) current.pop_front();
    } else {
      if (current.size() == m) {
        identity[current.back()] = index;
        current.pop_back();
      } else if (current.size() == m - 1)
        tight = true;
      current.push_back(index);
      open.insert(index);
    }
  }
  if (!tight) {
    cout << "No solution\n";
    return 0;
  }
  int id = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (!identity[i])
      identity[i] = ++id;
    else
      identity[i] = identity[identity[i]];
  }
  cout << id << "\n";
  for (int i = 0; i < n; i++) cout << identity[i] << "\n";
};
