import bisect



q = int(input())

M = {}
list_key_sorted = []

for _ in range(q):
    
    command, *list_num = input().split()

    if   command == "0":
        # insert(key, x)
        key = list_num[0]
        x = int(list_num[1])

        if key not in M:
            bisect.insort_left(list_key_sorted, key)

            M[key] = []

        M[key].append(x)
    elif command == "1":
        # get(key)
        key = list_num[0]
        if key in M:
            if M[key]:
                for value in M[key]:
                    print(value)
    elif command == "2":
        # delete(key)
        key = list_num[0]
        if key in M:
            M[key] = []
    elif command == "3":
        # dump(L, R)
        L = list_num[0]
        R = list_num[1]

        index_left = bisect.bisect_left(list_key_sorted, L)
        index_right = bisect.bisect_right(list_key_sorted, R)

        for index in range(index_left, index_right):
            key_ans = list_key_sorted[index]
            if M[key_ans]:
                for value_ans in M[key_ans]:
                    print(key_ans, value_ans)
    else:
        raise

