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

int main()
{
	multimap<string, int> cpp;
	string str, v;
	int n, com, q;
	cin >> q;

	while (q--)
	{
		cin >> com >> str;
		multimap<std::string, int>::iterator iter,prev;

		switch (com)
		{
		case 0:
			cin >> n;
			cpp.insert(make_pair(str, n));
			break;
		case 1:
			iter = cpp.lower_bound(str);
			for (; iter != cpp.end() && (iter->first) == str; ++iter)
				cout << iter->second << endl;
			break;                                          
		case 2:
			cpp.erase(str);
			break;
		case 3:
			cin >> v;
			for (prev = cpp.lower_bound(str); prev != cpp.upper_bound(v); prev++)   
					cout << prev->first << " " << prev->second << endl;
			break;
		}
	}
	return 0;
}
