#include<iostream>
#include<tuple>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
using namespace std;

#define INF ((int)(1e9))
#define MAX 110000

int n, k, a, q, query, x;
string key, y;
multimap<string,int> se;

int main(){
	cin>>q;
	
	for(int i = 0; i < q; i++){
		cin>>query>>key;
		if(!query){
			cin>>x;
			se.insert(make_pair(key,x));
		} else if(query == 1){
			decltype(se)::iterator it = se.lower_bound(key), it2 = se.upper_bound(key);
			for(int i = 0; it != it2; i++,it++) if((*it).second)cout<<(*it).second<<endl;
		} else if(query == 2){
			se.erase(key);
		} else if(query == 3){
			cin>>y;
			decltype(se)::iterator it = se.lower_bound(key), it2 = se.upper_bound(y);
			for(int i = 0; it != it2; i++,it++) if((*it).second)cout<<(*it).first<<" "<<(*it).second<<endl;
		}
	}
	return 0;
}
