#include <bits/stdc++.h>

using namespace std;


int main(){
    int num_query;
    int command,val;
    char key[20];
    char L[20],R[20];
    scanf("%d",&num_query);
    multimap<string,int> map_array;

    for(int i = 0;i < num_query;i++){
        scanf("%d %s",&command,key);
        if(command == 0){
            scanf("%d",&val);
            map_array.insert(make_pair(key,val));
        }else if(command == 1){
            if(map_array.count(key) > 0){
                auto rg = map_array.equal_range(key);
                for(auto it = rg.first;it != rg.second;it++){
                    printf("%d\n",it->second);
                }
            }
        }else if(command == 2){
            if(map_array.find(key) != map_array.end()) map_array.erase(key);
        }else if(command == 3){
            scanf("%s",R);
            map<string,int>::iterator itr = map_array.lower_bound(key);
            while(itr != map_array.upper_bound(R)){
                printf("%s %d\n",itr->first.c_str(),itr->second);
                itr++;
            }
        }
    }

    return 0;   
}

