#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
multimap<string,int>mp;
int main() {
	int q;
	cin >> q;
	while (q--) {
		int Q;
		cin >> Q;
		string s, l, r;
		int x;
		if (Q == 0) {
			cin >> s >> x;
			mp.insert(make_pair(s, x));
		}
		if (Q == 1) {
			cin >> s;
			for (auto it = mp.lower_bound(s); it != mp.end() && it->first == s; it++) {
				cout << it->second << endl;
			}
		}
		if (Q == 2){
			cin >> s;
			mp.erase(s);
		}
		if (Q == 3) {
			cin >> l >> r;
			auto now = mp.lower_bound(l);
			auto end = mp.upper_bound(r);
			assert(l <= r);
			while (now!=end) {
				cout << now->first << " " << now->second << endl;
				++now;
			}
		}
	}
	return 0;
}
