#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

int calcTime(int h1, int m1, int h2, int m2){
    int t1, t2;
    t1 = h1*60 + m1;
    t2 = h2*60 + m2;
    return t2 - t1;
}

signed main(){
    int M, t;
    cin >> M >> t;
    vector<pair<string, int> > d;
    int h, m, hp, mp;
    string name;
    rep(i, 0, 2 * M){
        scanf("%d:%d ",&h, &m);
        cin >> name;
        if(i % 2){
            //name = s;
            hp = h;
            mp = m;
        }else if(i % 2 == 0 && i != 0){
            int tmp = calcTime(hp, mp, h, m);
            //cout << tmp << " " << name << endl;
            if(tmp >= t){
                d.push_back(make_pair(name, tmp));
            }
        }
    }
    cout << d.size() <<endl;
    rep(i, 0, d.size()){
        cout << d[i].first <<" "<< d[i].second << endl;
    }
}