#include <bits/stdc++.h>
using namespace std;
multimap<string, int> mp;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int Q;
    cin >> Q;
    string s, l, r;
    int x;
    if (Q == 0) {
      cin >> s >> x;
      mp.insert(make_pair(s, x));
    }
    if (Q == 1) {
      cin >> s;
      auto now = mp.lower_bound(s);
      while (now->first == s) {
        cout << now->second << endl;
        ++now;
      }
    }
    if (Q == 2) {
      cin >> s;
      mp.erase(s);
    }
    if (Q == 3) {
      cin >> l >> r;
      auto now = mp.lower_bound(l);
      auto end = mp.upper_bound(r);
      while (now != end) {
        if (now->second) cout << now->first << " " << now->second << endl;
        ++now;
      }
    }
  }
  return 0;
}
