#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;


int a[200010];
int b[200010];
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    typedef multimap<string, int> MCI;
    MCI mp;
    REP(i, n){
        ll a; string b; cin >> a;
        if(a==0){
            int c;
            cin >> b >> c;
            mp.insert(MCI::value_type(b, c));
        
        }else if(a==1){
            cin >> b;
            pair<MCI::iterator, MCI::iterator> p = mp.equal_range(b);
            for(MCI::iterator it = p.first; it!=p.second; ++it){
                if(it->second) cout << it->second << endl;
            }
        }else if(a==2){
            cin >> b;
            pair<MCI::iterator, MCI::iterator> p = mp.equal_range(b);
            for(MCI::iterator it = p.first; it!=p.second; ++it){
                it->second=0;
            }
        }else if(a==3){
            string c;
            cin >> b >> c;
            for(auto it=mp.lower_bound(b); it!=mp.upper_bound(c); ++it){
                if((*it).second) cout << (*it).first << " " << (*it).second << endl;
            }
            
        }
    }
	return 0;
}
