#include <iostream>
#include <map>
#include <set>
#include <string>
#define int long long
using namespace std;
multimap<string, int>m;
set<string>s;
signed main() {
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int p; string k, l, r;
		cin >> p;
		if (p == 0) {
			cin >> k >> p;
			s.insert(k); m.insert(make_pair(k, p));
		}
		else if (p == 1) {
			cin >> k;
			for (auto i = m.lower_bound(k); i != m.upper_bound(k); i++)	cout << i -> second << endl;

		}
		else if (p == 2) {
			cin >> k;
			s.erase(k);
			m.erase(m.equal_range(k).first, m.equal_range(k).second);
		}
		else {
			cin >> l >> r;
			for (auto i = m.lower_bound(l); i != m.upper_bound(r); i++)cout << i -> first << ' ' << i -> second << endl;
		}
	}
}
