#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,q,x;
    string s,l,r;
    std::multimap<string, long long int> map;
    cin>>n;
    for (int i=0;i<n;i++) {
        cin>>q;
        if (q==0) {
            cin>>s>>x;
            map.emplace(make_pair(s,x));
        } else if (q==1) {
            cin>>s;
            using iterator = decltype(map)::iterator;
            pair<iterator,iterator>ret=map.equal_range(s);
            for (auto it1=ret.first;it1!=ret.second;it1++) {
                cout<<it1->second<<endl;
            }
        } else if (q==2) {
            cin>>s;
            map.erase(s);
        } else if (q==3) {
            cin>>l>>r;
            auto itr3=map.lower_bound(l);
            auto itr4=map.upper_bound(r);
            for (auto it=itr3;it!=itr4;it++) {
                cout<<it->first<<" "<<it->second<<endl;
            }
        }
    }
}

