#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  multimap<string,int> mp;
  int q;
  cin >> q;
  REP(i,q){
    int t;
    string key;
    cin >> t >> key;
    if(t==0){
      int x;
      cin >> x;
      mp.insert({key,x});
    }else if(t==1){
      auto itr = mp.lower_bound(key);
      auto itr2 = mp.upper_bound(key);
      for(auto i = itr;i!=itr2;++i){
        cout << i->second << endl;
      }
    }else if(t==2){
      mp.erase(key);
    }else{
      auto itr = mp.lower_bound(key);
      string r;
      cin >> r;
      auto itr2 = mp.upper_bound(r);
      for(auto i = itr;i!=itr2;++i){
        cout << i->first << " " << i->second << endl;
      }
    }
  }
}

