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

int main() {
  int q; cin >> q;
  multimap<string, int> mp;
  for (int i = 0; i < q; i++) {
    int cmd; cin >> cmd;
    if (cmd == 0) {
      string key; int x; cin >> key >> x;
      mp.insert(make_pair(key, x));
    }
    if (cmd == 1) {
      string key; cin >> key;
      auto r = mp.equal_range(key);
      for (auto itr = r.first; itr != r.second; itr++) {
        cout << itr -> second << endl;
      }
    }
    if (cmd == 2) {
      string key; cin >> key;
      mp.erase(key);
    }
    if (cmd == 3) {
      string l, r; cin >> l >> r;
      for (auto itr = mp.lower_bound(l), end = mp.upper_bound(r); itr != end; itr++) {
        cout << itr -> first << " " << itr -> second << endl;
      }
    }
  }
}

