#include <iostream>
#include <string>

using namespace std;

int main() {
	int n, t;
	cin >> n >> t;
	string eki[10];
	int ekii[10];
	int counter = 0;
	string pss, pas, nss, nas;
	int pst, pat, nsh, nsm, nah, nam;
	char c;
	for (int i = 0; i < n; i++) {
		cin >> nsh >> c >> nsm >> nss >> nah >> c >> nam >> nas;
		if (i == 0) {
			pst = nsh * 60 + nsm;
			pat = nah * 60 + nam;
			pss = nss;
			pas = nas;
		} else {
			if ((nsh * 60 + nsm) - pat >= t) {
				eki[counter] = nss;
				ekii[counter] = (nsh * 60 + nsm) - pat;
				counter++;
			}
			pst = nsh * 60 + nsm;
			pat = nah * 60 + nam;
			pss = nss;
			pas = nas;
		}
	}
	if (counter == 0) {
		cout << 0 << endl;
	} else {
		cout << counter << endl;
		for (int i = 0; i < counter; i++) {
			cout << eki[i] << " " << ekii[i] << endl;
		}
	}
	return 0;
}