#include <iostream>
#include <string>
#include <map>

int main() {
    std::multimap<std::string, int> mp;
    int Q;
    std::cin >> Q;

    for (int q = 0; q < Q; ++q) {
        int t;
        std::cin >> t;
        if (t == 0) {
            std::string k;
            int x;
            std::cin >> k >> x;
            mp.emplace(k, x);
        } else if (t == 1) {
            std::string k;
            std::cin >> k;
            auto p = mp.equal_range(k);
            for (auto itr = p.first; itr != p.second; ++itr) {
                std::cout << itr->second << std::endl;
            }
        } else if (t == 2) {
            std::string k;
            std::cin >> k;
            mp.erase(k);
        } else {
            std::string l, r;
            std::cin >> l >> r;
            auto e = mp.upper_bound(r);
            for (auto itr = mp.lower_bound(l); itr != e; ++itr) {
                std::cout << itr->first << " " << itr->second << std::endl;
            }
        }
    }
}
