#include<iostream>
#include<map>
using namespace std;

int main(){

    int q;
    cin >> q;
    multimap<string, int> mp;
    for(int i = 0; i < q; ++i){
        int com;
        string key;
        cin >> com;
        if(com != 3){
            cin >> key;
        } 

        if(com == 0){
            int x;
            cin >> x;
            mp.emplace(key, x);
        }
        else if(com == 1){
            auto p = mp.equal_range(key);
            for (auto it = p.first; it != p.second; ++it) {
                cout << it->second << endl;
            }
        }
        else if(com == 2){
            mp.erase(key);
        }
        else{
            string L, R;
            cin >> L >> R;
            auto l = mp.lower_bound(L);
            auto r = mp.upper_bound(R);
            for(auto it = l; it != r; ++it){
                cout << it->first << " " << it->second << endl;
            }
        }
    }

    return 0;
}
