#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y;
  point() {}
  point(int a, int b) { x = a, y = b; }
};
template <class T>
T sqr(T a) {
  return a * a;
}
template <class T>
T power(T n, T p) {
  T res = 1;
  for (int i = 0; i < p; i++) res *= n;
  return res;
}
template <class T>
double getdist(T a, T b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
template <class T>
T extract(string s, T ret) {
  stringstream ss(s);
  ss >> ret;
  return ret;
}
template <class T>
string tostring(T n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
struct fast {
  fast() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  }
} cincout;
vector<int> res;
deque<int> dq;
int main() {
  int n, M, t, i, h, m, s, x;
  char dummy;
  cin >> n >> M >> t;
  int cur = 0, nos = 1;
  for (i = 0; i < n; i++) {
    cin >> h >> dummy >> m >> dummy >> s;
    x = h * 3600 + m * 60 + s;
    while (!dq.empty() && dq.front() + t - 1 < x) dq.pop_front();
    if ((int)(dq.size()) < M)
      ++cur;
    else
      dq.pop_back();
    res.push_back(cur);
    dq.push_back(x);
    if ((int)(dq.size()) == M) nos = 0;
  }
  if (nos) {
    cout << "No solution";
    return 0;
  }
  cout << cur << "\n";
  for (auto x : res) cout << x << "\n";
  return 0;
}
