#include<iostream>
#include<vector>
#include<utility>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int tm(string s){
	long long res=((s[0]-'0')*10+(s[1]-'0'))*60+(s[3]-'0')*10+(s[4]-'0');
	return res;
}

int main(){
	long long n,t;
	cin>>n>>t;
	string st[n];
	string ar[n];
	string stn[n];
	string arn[n];
	vector<pair<string,long long> > vec;
	rep(i,n){
		cin>>stn[i]>>st[i]>>arn[i]>>ar[i];
	}
	rep(i,n-1){
		if(tm(stn[i+1])-tm(arn[i])>=t){
			pair<string,int> pr;
			pr.first=ar[i];
			pr.second=tm(stn[i+1])-tm(arn[i]);
			vec.push_back(pr);
		}
	}
	cout<<vec.size()<<endl;
	rep(i,vec.size()){
		pair<string,int> ans=vec[i];
		cout<<ans.first<<" "<<ans.second<<endl;
	}
	return 0;
}