import bisect
from collections import defaultdict

def main():

    q = int(input())
    d = defaultdict(list)

    inserted_flag = False
    sorted_keys = None

    for _ in range(q):
        para = input().split()

        if para[0] == "0":
            d[para[1]].append(int(para[2])) 
            inserted_flag = True

        elif para[0] == "1":
            if para[1] in d.keys():
                for i in range(len(d[para[1]])):
                        print(d[para[1]][i])
                        
        elif para[0] == "2":
            if para[1] in d.keys():
                del d[para[1]]
                inserted_flag = True
            
        elif para[0] == "3":
            if sorted_keys is None:
                sorted_keys = sorted(d.keys())

            if inserted_flag:
                sorted_keys = sorted(d.keys())
                inserted_flag = False

            l = bisect.bisect_left(sorted_keys, para[1])
            r = bisect.bisect_right(sorted_keys, para[2])

            for i in range(l, r):
                for j in range(len(d[sorted_keys[i]])):
                    print("{} {}".format(sorted_keys[i], d[sorted_keys[i]][j]))

main()
