#include <iostream>
#include <map>
#include <string>

int main(int argc, char *argv[]) {
  int q;
  std::cin >> q;
  std::multimap<std::string, long> m;
  for (int i = 0; i < q; ++i) {
    int c;
    std::string key;
    std::cin >> c >> key;
    switch (c) {
    case 0:
      int x;
      std::cin >> x;
      m.insert({key, x});
      break;
    case 1:
      if (m.find(key) != m.end()) {
        auto r = m.equal_range(key);
        for (auto i = r.first; i != r.second; ++i) {
          std::cout << i->second << std::endl;
        }
      }
      break;
    case 2:
      m.erase(key);
      break;
    case 3:
      std::string r;
      std::cin >> r;
      auto begin = m.lower_bound(key), end = m.upper_bound(r);
      for (auto i = begin; i != end; ++i) {
        std::cout << i->first << " " << i->second << std::endl;
      }
      break;
    }
  }
}

