#include<bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;
typedef pair<int, int> P;

#define MAX 100005
#define INF 1001001001

int main(int, char**)
{
  multimap<string, int> a;
  int q;
  cin >> q;
  vector<string> ans;
  rep(i,q) {
    int command; cin >> command;
    if (command == 0) {
      string key;
      int x;
       cin >> key >> x;
      a.emplace(key,x);
    } else if (command == 1) {
      string key; cin >> key;
      auto itre = a.equal_range(key);
      for (auto itr = itre.first; itr != itre.second; itr++) {
        stringstream ss;
        ss << (*itr).second;
        ans.push_back(ss.str());
      }
    } else if (command == 2) {
      string key; cin >> key;
      a.erase(key);
    } else if (command == 3) {
      string l, r; cin >> l >> r;
      auto itr1 = a.lower_bound(l);
      auto itr2 = a.upper_bound(r);
      for (auto itr = itr1; itr != itr2; itr++) {
        stringstream ss;
        ss << (*itr).first << " " << (*itr).second;
        ans.push_back(ss.str());
      }
    }
  }

  for (auto a : ans) cout << a << endl;

  return 0;
}

