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

int main()
{
	long q;
	cin >> q;

	multimap <string, long> mp;

	for (long i = 0; i < q; i++) {
		int t;
		cin >> t;

		string s;
		cin >> s;

		if (t == 0) {
			long x;
			cin >> x;
			mp.insert(std::make_pair(s, x));
		}
		else if (t == 1) {
			std::map<string, long>::iterator itr = mp.find(s);
			if (itr != mp.end()) {
				while (itr != mp.end() && itr->first == s) {
					cout << itr->second << endl;
					itr++;
				}
			}
		}
		else if (t == 2)
			mp.erase(s);
		else if (t == 3) {
			string r;
			cin >> r;
			std::map<string, long>::iterator itr;
			for (itr = mp.lower_bound(s); itr != mp.upper_bound(r); itr++)
				cout << itr->first << " " << itr->second << endl;
		}
	}

	return 0;
}
