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

int main() {
  int num_query; cin >> num_query;
  multimap<string, int> dic;
  
  while (num_query--) {
    int command; scanf("%d", &command);
    char key[20]; scanf("%s", key);
    
    switch (command) {
      case 0:
        int value; scanf("%d", &value);
        dic.insert(make_pair(key, value));
        break;
        
      case 1:
        {
          pair<multimap<string, int>::iterator, multimap<string, int>::iterator> 
            range = dic.equal_range(key);
          while (range.first != range.second) {
            printf("%d\n", range.first -> second);
            range.first++;
          }
          break;
        }
        
      case 2:
        dic.erase(key);
        break;
        
      case 3:
        char key2[20]; scanf("%s", key2);
        multimap<string, int>::iterator it = dic.lower_bound(key);
        multimap<string, int>::iterator last = dic.upper_bound(key2);
        while (it != last) {
          printf("%s %d\n", ((*it).first).c_str(), (*it).second);
          it++;
        }
        break;
    }
  }
}
