#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int q; cin >> q;
    multimap<string,int> m;
    rep(i ,q){
        int man; cin >> man;
        string key;
        int x;
        decltype(m)::iterator itr;
        decltype(m)::iterator itr1;
        decltype(m)::iterator itr2;
        switch (man)
        {
            case 0:
                cin >> key >> x;
                m.insert(make_pair(key,x));
                break;
            case 1:
                cin >> key;
                itr1 = m.lower_bound(key);
                itr2 = m.upper_bound(key);
                itr = itr1;
                for(; itr!=itr2;++itr){
                    cout << itr->second << endl;
                }
                break;
            case 2:
                cin >> key;
                m.erase(key);
                break;
            case 3:
                string l , r;
                cin >> l >> r;
                itr1 = m.lower_bound(l);
                itr2 = m.upper_bound(r);
                itr = itr1;
                for(;itr!=itr2;++itr){
                    cout << itr->first << " " << itr->second << endl;
                }
                break;
        }
    }
}
