#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int q;
    cin>>q;

    multimap<string,int> mp;
    while(q--){
        int op;
        string s;
        cin>>op>>s;
        switch(op)
        {
            case 0:
                int x;
                cin>>x;
                mp.insert(make_pair(s,x));
                break;
            case 1:

                {auto range=mp.equal_range(s);
                for(auto i=range.first;i!=range.second;i++)
                {
                    cout<<i->second<<endl;
                }}
                break;
            case 2:
                mp.erase(s);
                break;
            case 3:
                string l=s,r;
                cin>>r;
                for(auto i=mp.lower_bound(l),e=mp.upper_bound(r);i!=e;i++)
                {
                    cout<<i->first<<" "<<i->second<<endl;
                }
                break;
        }
    }

    return 0;
}




