#include <iostream>
#include <map>
#include <string>
using namespace std;

int main() {
	int q, query, x;
	cin >> q;
	multimap<string, int> M;
	for (int i = 0; i < q; ++i) {
		cin >> query;
		if (0 == query) {
			string key;
			cin >> key >> x;
			M.emplace(key, x);
		}
		else if (1 == query) {
			string key;
			cin >> key;
			for (decltype(M)::iterator i = M.equal_range(key).first; i != M.equal_range(key).second; ++i) cout << i->second << endl;
		}
		else if (2 == query) {
			string key;
			cin >> key;
			M.erase(key);
		}
		else {
			string L, R;
			cin >> L >> R;
			for (multimap<string, int>::iterator i = M.lower_bound(L); i != M.upper_bound(R); ++i) cout << i->first << ' ' << i->second << endl;
		}
	}
}
