#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int q;
    cin>>q;
    multimap<string, int> mp;
    rep(i, q) {
        int c;
        cin>>c;
        if (c == 0) {
            string k;
            cin>>k;
            int x;
            cin>>x;
            mp.emplace(k, x);
        }
        else if (c == 1) {
            string k;
            cin>>k;
            auto p = mp.equal_range(k);
            for (auto it = p.first; it != p.second; ++it) {
                cout<<(*it).second<<endl;
            }
        }
        else if (c == 2) {
            string k;
            cin>>k;
            mp.erase(k);
        }
        else {
            string l, r;
            cin>>l>>r;
            auto it = mp.lower_bound(l);
            auto cl = mp.upper_bound(r);
            for (; it != cl; it = next(it, 1)) {
                if ((*it).second == 0) continue;
                cout<<(*it).first<<" "<<(*it).second<<endl;
            }
        }
    }
}
