@staticmethod
def d():

    def to_minuites(x):
        (q, r) = divmod(x, 100)
        return ((60 * q) + r)

    def to_hmform(x):
        (q, r) = divmod(x, 60)
        return ((100 * q) + r)
    n = int(sys.stdin.readline().rstrip())
    term = ([0] * 2001)
    for _ in range(n):
        (s, e) = map(to_minuites, map(int, sys.stdin.readline().rstrip().split('-')))
        s = ((s // 5) * 5)
        e = (((e + 4) // 5) * 5)
        term[s] += 1
        term[(e + 1)] -= 1
    for i in range(2000):
        term[(i + 1)] += term[i]
    res = []
    raining = False
    for i in range(2001):
        if term[i]:
            if (not raining):
                s = i
                raining = True
        elif raining:
            res.append((s, (i - 1)))
            raining = False
    for (s, e) in res:
        print(f'{to_hmform(s):04}-{to_hmform(e):04}')
@staticmethod
def d():

    def to_minuites(x):
        (q, r) = divmod(x, 100)
        return ((60 * q) + r)

    def to_hmform(x):
        (q, r) = divmod(x, 60)
        return ((100 * q) + r)
    n = int(sys.stdin.readline().rstrip())
    term = ([0] * 2001)
    for _ in range(n):
        (s, e) = map(to_minuites, map(int, sys.stdin.readline().rstrip().split('-')))
        s = ((s // 5) * 5)
        e = (((e + 4) // 5) * 5)
        term[s] += 1
        term[(e + 1)] -= 1
    for i in range(2000):
        term[(i + 1)] += term[i]
    res = []
    raining = False
    for i in range(2001):
        if term[i]:
            if (not raining):
                s = i
                raining = True
        elif raining:
            res.append((s, (i - 1)))
            raining = False
    for (s, e) in res:
        print(f'{to_hmform(s):04}-{to_hmform(e):04}')