#include <iostream>
#include <vector>
using namespace std;

int toMin(string s){
  int h = (s[0] - '0') * 10 + (s[1] - '0');
  int m = (s[3] - '0') * 10 + (s[4] - '0');
  return h * 60 + m;
}

int n, m;
int f_tm[12], t_tm[12];
string f_nm[12], t_nm[12];

int main(){
  while(cin >> n >> m){
    string s;

    for(int i = 0; i < n; i++){
      cin >> s >> f_nm[i];
      f_tm[i] = toMin(s);
      cin >> s >> t_nm[i];
      t_tm[i] = toMin(s);
    }

    vector<string> nm;
    vector<int> tm;

    for(int i = 1; i < n; i++){
      if(f_tm[i] - t_tm[i - 1] >= m){
        nm.push_back(f_nm[i]);
        tm.push_back(f_tm[i] - t_tm[i - 1]);
      }
    }

    cout << nm.size() << endl;

    for(int i = 0; i < nm.size(); i++){
      cout << nm[i] << " " << tm[i] << endl;
    }
  }
}