#include <bits/stdc++.h>
using namespace std;
int n, m, t;
struct my {
  int time;
  int color;
  my() {
    time = 0;
    color = 0;
  }
  my(int a, int b) {
    time = a;
    color = b;
  }
};
bool operator<(const my a, const my b) {
  if (a.time != b.time) {
    return a.time < b.time;
  } else {
    return a.color < b.color;
  }
}
set<my> st;
int r = 0;
vector<int> ans;
bool flg = false;
int main() {
  cin >> n >> m >> t;
  for (int i = 0; i < m; ++i) {
    st.insert(my(-1, i));
  }
  for (int i = 0; i < n; ++i) {
    int at, bt, ct;
    char ch;
    int in;
    cin >> at >> ch >> bt >> ch >> ct;
    in = at * 60 * 60 + bt * 60 + ct;
    if (st.begin()->time <= in) {
      my tt = *(st.begin());
      st.erase(st.begin());
      tt.time = in + t;
      tt.color = ++r;
      ans.push_back(r);
      st.insert(tt);
    } else {
      my tt = *(--st.end());
      st.erase(--st.end());
      tt.time = in + t;
      ans.push_back(tt.color);
      st.insert(tt);
    }
    if (st.begin()->time > in) {
      flg = true;
    }
  }
  if (flg) {
    cout << r << "\n";
    for (int i = 0; i < n; ++i) {
      cout << ans[i] << "\n";
    }
  } else {
    cout << "No solution";
  }
  return 0;
}
