//map_range_search
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vecll = vector<long long>;
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)

int main()
{
    multimap<string, ll> M;
    string key, R, L;
    ll q, que, x;

    cin >> q;
    rep(i, q)
    {
        //input_分けたい
        //cin >> que >> ((que == 3) ? L : key); //使えない??
        cin >> que;

        //que
        switch (que)
        {
        case 0:
            cin >> key >> x;
            M.insert({key, x});
            break;
        //M.insert_or_assign({key, x}); //C++17から
        case 1:
            cin >> key;
            for (auto itr = M.equal_range(key).first; itr != M.equal_range(key).second; itr++)
                cout << itr->second << endl;
            break;
        case 2:
            cin >> key;
            M.erase(key);
            break;
        case 3:
            cin >> L >> R;
            auto begin_itr = M.lower_bound(L);
            auto end_itr = M.upper_bound(R);
            //delctype(M)::iterator でも可能
            //map<string, ll>::iterator begin_itr = M.lower_bound(L);
            //map<string, ll>::iterator end_itr = M.upper_bound(R);
            for (auto itr = begin_itr; itr != end_itr; itr++)
                cout << itr->first << ' ' << itr->second << endl;
            //ポインタがさす構造体.メンバ名
            //cout << (*itr).first << ' ' << (*itr).second << endl;
            break;
        }

        /* //C++17から
            for (const auto &[a, b] : M)
            {
                cout << b << endl;
            }*/
    }
}
