#include <iostream>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
using namespace std;

int main()
{
    multimap<string,int> mp;
    map<string,int>::iterator  it;
    int tp,q,val;
    string key;
    string r,l;
    cin>>q;
    while(q--){
        cin>>tp;
        if(tp==1)
        {
            cin>>key;
            it=mp.lower_bound(key);
            while(it!=mp.end()&&it->first==key){
                    cout<<it->second<<"\n";
                    it++;
            }

        }
        else if(tp==0){
            cin>>key>>val;
            //mp[key]=val;
            mp.insert(pair<string,int>(key,val));
        }
        else if(tp==2){
            cin>>key;
            if(mp.find(key)!=mp.end())mp.erase(key);
        }
        else if(tp==3){
            cin>>l>>r;
            it=mp.lower_bound(l);

            while(it!=mp.end()&&it->first<=r){
                cout<<it->first<<" "<<it->second<<"\n";
                it++;
            }
        }
    }
}



