#include <iostream>
#include <map>

using Key = std::string;

int main(void) {
    int q;
    std::cin >> q;

    std::multimap<Key, int> my_multi_map{};
    using Iterator = decltype(my_multi_map)::iterator;
    for (int i = 0; i < q; ++i) {
        int kind;
        std::cin >> kind;

        Key key;
        int x;
        std::pair<Iterator, Iterator> range;
        switch (kind) {
            case 0:
                std::cin >> key >> x;
                my_multi_map.insert(std::pair<Key, int>(key, x));
                break;
            case 1:
                std::cin >> key;
                range = my_multi_map.equal_range(key);
                for (Iterator iter = range.first; iter != range.second;
                     ++iter) {
                    std::cout << iter->second << std::endl;
                }
                break;
            case 2:
                std::cin >> key;
                my_multi_map.erase(key);
                break;
            case 3:
                Key left, right;
                std::cin >> left >> right;
                for (auto iter = my_multi_map.lower_bound(left);
                     iter != my_multi_map.upper_bound(right); ++iter) {
                    std::cout << iter->first << ' ' << iter->second
                              << std::endl;
                }
        }
    }
}
