#include <iostream>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

int main() {
	multimap<string, int> M;
	int q;
	cin >> q;
	int query, x;
	string key;
	multimap<string, int>::iterator itr;
	string L, R;

	for (int i = 0; i < q; i++) {
		cin >> query >> key;
		if (query == 0) {
			cin >> x;
			M.insert(make_pair(key, x));
		}
		else if(query == 1){
			pair<multimap<string, int>::iterator, multimap<string, int>::iterator >
			its = M.equal_range(key);

			for (multimap<string, int>::iterator it = its.first; it != its.second; it++) {
				cout << it->second << endl;
			}
		}	
		else if(query == 2){
			M.erase(key);
		}
		else {
			L = key;
			cin >> R;
			
			for (auto it = M.lower_bound(L); it != M.upper_bound(R); it++)
				cout << it->first << " " << it->second << endl;
		}
	}
}
