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

int main(){
  multimap<string, int> M;
  int q, query, x;
  string key, L, R;
  cin >> q;
  for(int i = 0; i < q; i++){
    cin >> query;
    if(query == 0){
      cin >> key >> x;
      M.insert(make_pair(key, x));
    }else if(query == 1){
      cin >> key;
      for(auto it = M.lower_bound(key); it != M.end() && it->first == key; it++){
         cout<<it->second<<endl;
       }
    }else if(query == 2){
      cin >> key;
      M.erase(key);
    }else{
      cin >> L >> R;
      auto lb = M.lower_bound(L);
      auto ub = M.upper_bound(R);
      for(auto it = lb; it !=  ub; it++){
        cout<< it->first << " " << it->second << endl;
      }
    }
  }
  return 0;
}
