#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    int q;
    cin >> q;
    multimap<string, int> map;
    while (q--)
    {
        int c;
        cin >> c;
        if (c == 0)
        {
            string key;
            int x;
            cin >> key >> x;
            map.insert(pair<string,int>(key,x));
        } else if (c == 1)
        {
            string key;
            cin >> key;
            auto it = map.find(key);
            auto its=map.lower_bound(key);
            auto ise=map.upper_bound(key);
            if (its!=ise)
            {
                for (auto i = its; i !=ise ; ++i)
                {
                    cout << i->second << endl;
                }
            }
        } else if (c == 2)
        {
            string key;
            cin >> key;
            map.erase(key);
        } else
        {
            string L, R;
            cin >> L >> R;
            auto its = map.lower_bound(L);
            auto ite = map.upper_bound(R);
            for (auto i = its; i != ite; ++i)
            {
                cout << i->first << " " << i->second << endl;
            }
        }

    }

}
