#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int q,c,x;
	string key,L,R;
	cin >> q;
	multimap<string,int> ma;
	while(q--){
		cin >> c >> key;
		if(c==0){
			cin >> x;
			ma.insert({key,x});
		}else if(c==1){
			using iterator = decltype(ma)::iterator;
			pair<iterator,iterator> ret = ma.equal_range(key);
			for (auto it = ret.first; it != ret.second; ++it) {
				cout << it->second << "\n";
			}
		}else if(c==2){
			ma.erase(key);
		}else if(c==3){
			L = key;
			cin >> R;
			using iterator = decltype(ma)::iterator;
			pair<iterator,iterator> ret1 = ma.equal_range(L);
			pair<iterator,iterator> ret2 = ma.equal_range(R);
			for (auto it = ret1.first; it != ret2.second; ++it) {
				cout << it->first << " " << it->second << "\n";
			}
		}
	}
}
