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

int toInt(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 main(){
  int n, m;
  int st_time[12], ar_time[12];
  string st_name[12], ar_name[12];

  while(cin >> n >> m){
    for(int i = 0; i < n; i++){
      string s;
      cin >> s;
      st_time[i] = toInt(s);

      cin >> st_name[i];

      cin >> s;
      ar_time[i] = toInt(s);

      cin >> ar_name[i];
    }

    vector<string> ans;
    vector<int> ansTime;

    for(int i = 1; i < n; i++){
      if(st_time[i] - ar_time[i - 1] >= m){
        ans.push_back(st_name[i]);
        ansTime.push_back(st_time[i] - ar_time[i - 1]);
      }
    }

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

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