#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;
		switch (Q) {
		case 0:
			cin >> s >> x;
			mp.insert(make_pair(s, x));
			break;
		case 1:
			cin >> s;
			auto now = mp.lower_bound(s);
			while (now == mp.lower_bound(s)) {
				if (now->second)cout << now->second << endl;
				++now;
			}
			break;
		case 2:
			cin >> s;
			mp.erase(s);
			break;
		case 3:
			cin >> l >> r;
			auto now = mp.lower_bound(l);
			auto end = mp.upper_bound(r);
			while (now != end) {
				if (now->second)cout << now->first << " " << now->second << endl;
				++now;
			}
			break;
		}
	}
	return 0;
}
