#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

int main() {
  int q;
  cin >> q;
  string k;
  multimap<string, int> M;
  while (cin >> q >> k) {
    if (q == 0) {
      int x;
      cin >> x;
      M.insert({k, x});
    }
    if (q == 1) {
      auto p = M.equal_range(k);
      while (p.first != p.second)
        cout << (*(p.first++)).second << endl;
    }
    if (q == 2)
      M.erase(k);
    if (q == 3) {
      string r;
      cin >> r;
      auto lo = M.lower_bound(k);
      auto hi = M.upper_bound(r);
      while (lo != hi) {
        auto p = *(lo++);
        cout << p.first << " " << p.second << endl;
      }
    }
  }
}
