#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t,i,z,x;
    string s,l,r;
    multimap<string,int>m;
    multimap<string,int>::iterator it,ut;
    cin>>t;
    for (i=1;i<=t;++i){

        cin>>x;
        if (x==0){

            cin>>s>>z;
            m.insert(make_pair(s,z));

        }
        else if (x==1){

            cin>>s;
            it=m.lower_bound(s);
            for (;it!=m.end() && (it->first)==s;++it){



                    cout<<(it->second)<<endl;


            }

        }
        else if (x==2){

            cin>>s;
            m.erase(s);

        }
        else if (x==3){

            cin>>l>>r;
            it=m.lower_bound(l);
            ut=m.upper_bound(r);
            //ass
            for (;it!=ut;++it){

                cout<<(it->first)<<' '<<(it->second)<<endl;

            }
        }
    }

    return 0;
}

