#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
	int	N;
	cin >> N;
	multimap<string, int> m;
	using iterator = decltype(m)::iterator;
	rep(i, N)
	{
		int	a;
		string b;
		cin >> a >> b;
		if (a == 0)
		{
			int c;
			cin >> c;
			m.insert(make_pair(b, c));
			/* m[b] = c; */
		}
		else if (a == 1)
		{

			/* pair<iterator, iterator> p = m.equal_range(b); */
			/* for (iterator it = p.first; it != p.second; it++) */
			iterator x, y;
			x = m.lower_bound(b);
			y = m.upper_bound(b);
			for (iterator it = x; it != y; it++)
				cout << it->second << endl;
		}
		else if (a == 2)
			m.erase(b);
		else
		{
			string	c;
			cin >> c;
			/* for (map<string, int>::iterator it = m.lower_bound(b); it != m.upper_bound(c); it++) */
			for (auto it = m.lower_bound(b); it != m.upper_bound(c); it++)
				cout << it->first << ' ' << it->second << endl;
		}
	}
}

