import std.stdio;
import std.typecons;
import std.conv;

void main() {
    int N, T; readf("%d %d\n", &N, &T);
    int[string] times;
    string[] names;
    foreach (i; 0 .. N) {
        int h1, h2, m1, m2;
        string n1, n2;
        readf("%d:%d %s %d:%d %s\n", &h1, &m1, &n1, &h2, &m2, &n2);
        if (i != 0) {
            times[n1] += h1 * 60 + m1;
            names ~= n1;
        }
        if (i != N - 1) {
            times[n2] -= h2 * 60 + m2;
        }
    }
    string[] ans;
    foreach (name; names) {
        if (times[name] >= T) {
            ans ~= text(name, " ", times[name]);
        }
    }
    ans.length.writeln;
    foreach (a; ans) {
        a.writeln;
    }
}