#include<bits/stdc++.h>
using namespace std;

multimap<string,int> maap;
int x,q,tipe;
string r,l,key;

int main(){
    scanf("%d",&q);
    while(q--){
        scanf("%d",&tipe);
        if(tipe==0){
            cin>>key>>x;
            maap.insert(make_pair(key,x));
        } else if(tipe==1){
            cin>>key;
            int temp = maap.count(key);
            multimap <string,int>::iterator i;
            for (i = maap.equal_range(key).first;i!=maap.equal_range(key).second;i++)cout<<(*i).second<<endl;
        } else if(tipe==2){
            cin>>key;
            maap.erase(key);
        } else if(tipe==3){
            cin>>r>>l;
            multimap<string,int>::iterator itlow,itup;
            itlow = maap.lower_bound(r);
            itup = maap.upper_bound(l);
            for (auto i= itlow;i!=itup;i++){
                cout<<i->first<<" "<<i->second<<endl;
            }
        }
    }
return 0;
}

