#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const double EPS = 1e-15;
const double PI = acos(-1.0);
const int MAXN = (int)1e5 + 7;
const int INF = (int)1e9 + 7;
const long long LINF = (long long)2e18 + 7;
const int MOD = (int)1e9 + 7;
const unsigned long long P = 239017;
const unsigned long long MM = (unsigned long long)2147482661;
int solve();
int main() {
  solve();
  return 0;
}
struct event {
  int x, num, type;
};
vector<event> g;
int answer[MAXN];
int solve() {
  int n, m, t;
  cin >> n >> m >> t;
  for (int i = 0; i < (int)n; i++) {
    int hh, mm, ss;
    scanf("%d:%d:%d", &hh, &mm, &ss);
    int tin = hh * 3600 + mm * 60 + ss, tout = tin + t - 1;
    g.push_back({tin, i, 0});
    g.push_back({tout, i, 1});
  }
  sort(g.begin(), g.end(), [](event e1, event e2) {
    if (e1.x == e2.x) return e1.type < e2.type;
    return e1.x < e2.x;
  });
  int diff = 0, r = 0, maxm = 0;
  deque<int> dq;
  for (auto e : g) {
    if (e.type) {
      int x = dq.front();
      dq.pop_front();
      int y = dq.empty() ? -1 : dq.front();
      diff -= (x != y);
    } else {
      if (dq.empty()) {
        int ans = r + 1;
        r++;
        answer[e.num] = ans;
        diff++;
        dq.push_back(ans);
      } else {
        int ans = (diff == m ? dq.back() : dq.back() + 1);
        answer[e.num] = ans;
        diff += (dq.back() != ans);
        dq.push_back(ans);
        r = max(r, ans);
      }
      maxm = max(maxm, diff);
    }
  }
  if (maxm < m) {
    cout << "No solution\n";
    return 0;
  }
  cout << r << '\n';
  for (int i = 0; i < (int)n; i++) {
    cout << answer[i] << '\n';
  }
  return 0;
}
