#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void smax(T &x, T y) {
  x = max((x), (y));
}
template <class T>
inline void smin(T &x, T y) {
  x = min((x), (y));
}
const int MOD = 1e9 + 7;
const int SIZE = 1e5 + 10;
const long long INF = 1e15;
int n, m, t;
int calcsecs(string &str) {
  for (int i = 0; i < (((int)(str).size())); ++i)
    if (str[i] == ':') str[i] = ' ';
  stringstream SS;
  SS << str;
  int hh, mm, ss;
  SS >> hh >> mm >> ss;
  return hh * 60 * 60 + mm * 60 + ss;
}
int main() {
  if (0) {
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  }
  while (cin >> n >> m >> t) {
    vector<pair<int, int> > ans;
    int st = 0, ed = 0;
    int z = 0;
    bool ok = false;
    while (n--) {
      string s;
      cin >> s;
      int secs = calcsecs(s);
      while (st < ed && ans[st].second <= secs) st++;
      if (st == ed) {
        z++;
        ans.push_back(make_pair(z, secs + t));
        ed++;
      } else {
        int i = ans[st].first, j = ans[ed - 1].first;
        if (j - i + 1 < m) {
          z++;
          ans.push_back(make_pair(z, secs + t));
          ed++;
        } else {
          ans.push_back(make_pair(j, secs + t));
          ed++;
        }
      }
      int i = ans[st].first, j = ans[ed - 1].first;
      if (j - i + 1 == m) ok = true;
    }
    if (!ok)
      printf("No solution\n");
    else {
      printf("%d\n", z);
      for (int i = 0; i < (((int)(ans).size())); ++i)
        printf("%d\n", ans[i].first);
    }
  }
  return 0;
}
