from bisect import *
n = int(input())
dic = {}
dic2 = {}
box = []
for i in range(n):
    a, b, *c = input().split()
    if a == '0':
        insort_left(box, b)
        if b in dic:
            temp = dic[b]
            dic[b] = temp + [int(c[0])]
        else:
            dic[b] = [int(c[0])]
    elif a == '1':
        if b in dic:
            pri = []
            for i in dic[b]:
                pri.append(str(i))
            print("\n".join(pri))
    elif a == '2':
        if b in dic:
            del dic[b]
    else:
        L = bisect_left(box,b)
        R = bisect_right(box, c[0])
        while L<R:
            if box[L] in dic:
                for i in dic[box[L]]:
                    print(box[L], i)
            L = bisect_right(box, box[L])
        
        
