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

int main() {
 multimap<string,UL> S;
 UL Q; scanf("%u",&Q);
 rep(q,Q){
  UL c; scanf("%u",&c);
  if(c==0){
   char buf[21]; UL x; scanf("%s%u",buf,&x);
   S.emplace(buf,x);
  }
  if(c==1){
   char buf[21]; scanf("%s",buf);
   auto lb=S.lower_bound(buf);
   auto ub=S.upper_bound(buf);
   for(auto i=lb; i!=ub; i++){
    printf("%u\n",i->second);
   }
  }
  if(c==2){
   char buf[21]; scanf("%s",buf);
   S.erase(buf);
  }
  if(c==3){
   string L,R;
   char buf[21];
   scanf("%s",buf); L=string(buf);
   scanf("%s",buf); R=string(buf);
   auto f=S.lower_bound(L);
   for(;f!=S.end();f++){
    if(f->first>R) break;
    printf("%s %u\n",f->first.c_str(),f->second);
   }
  }
 }
 return 0;
}


