#include<bits/stdc++.h>
using namespace std;

signed main(){

  cin.tie(0);
  ios::sync_with_stdio(false);

  int q;
  cin>>q;
  multimap<string,int> mp;
  while(q--){
    int com;
    cin>>com;
    if(com==0){
      string k;
      int x;
      cin>>k>>x;
      mp.emplace(k,x);
    }
    else if(com==1){
      string k;
      cin>>k;
      auto p = mp.equal_range(k);
      for(auto itr=p.first;itr!=p.second;++itr){
        cout<< (*itr).second <<"\n";
      }
    }
    else if(com==2){
      string k;
      cin>>k;
      mp.erase(k);
    }
    else if(com==3){
      string l,r;
      cin>>l>>r;
      auto itr = mp.lower_bound(l);
      auto end = mp.upper_bound(r);
      while(itr!=end){
        cout<< (*itr).first <<" "<< (*itr).second <<"\n";
        itr++;
      }
    }
  }

}
