from bisect import bisect_left, bisect_right, insort_left
from typing import Dict, List


if __name__ == "__main__":
    num_query = int(input())
    d: Dict[str, List[int]] = {}
    keys: List[str] = []

    for _ in range(num_query):
        op, *v = input().split()
        if ("0" == op):
            if v[0] not in d:
                insort_left(keys, v[0])
                d[v[0]] = []
            d[v[0]].append(int(v[1]))
        elif ("1" == op):
            if v[0] in d:
                for elem in d[v[0]]:
                    print(elem)
        elif ("2" == op):
            if v[0] in d:
                d[v[0]] = []
        else:
            left_key = bisect_left(keys, v[0])
            right_key = bisect_right(keys, v[1], left_key)
            for k in range(left_key, right_key):
                for elem in d[keys[k]]:
                    print(keys[k], elem)

