#include <iostream>
#include <fstream>
#include <algorithm>
#include <map>
//#define LOCAL
using namespace std;
typedef long long ll;
multimap<string,ll>m;
typedef multimap<string, ll>::iterator mmi;

int main() {
#ifdef LOCAL
ifstream fin("1.txt");
streambuf*p;
p=cin.rdbuf(fin.rdbuf());
#endif // LOCAL
ll q;
cin>>q;
for(ll i=0;i<q;i++){
    ll a;
    string key;
    cin>>a>>key;
    if(0==a){
        ll x;
        cin>>x;
        pair<string, ll>p1(key, x);
        m.insert(p1);
    }else if(1==a){
        if(m.count(key)){
            pair<mmi, mmi>getm=m.equal_range(key);
            for(mmi it=getm.first;it!=getm.second;it++){
                cout<< it->second<<endl;
            }
        }
       // else cout<<'0'<<endl;
    }else if(2==a){
        m.erase(key);
    }else if(3==a){
        string r;
        cin>>r;
        map<string, ll>::iterator i1, i2;
        i1=m.lower_bound(key);
        i2=m.upper_bound(r);
        for(;i1!=i2;i1++){
            cout<<i1->first<<' '<<i1->second<<endl;
        }
    }
}

#ifdef LOCAL
fin.close();
#endif // LOCAL
}

