#include <bits/stdc++.h>
using namespace std;

int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int q, com, x;
	string key, L, R;
	multimap<string, int> my_map;
	multimap<string, int>::iterator it1, it2, it;

	cin >> q;
	while (q--) {
		cin >> com >> key;
		switch (com) {
			case 0:
				cin >> x;
				my_map.insert(make_pair(key, x));
				break;
			case 1:
				it1 = my_map.lower_bound(key);
				it2 = my_map.upper_bound(key);
				for (it = it1; it != it2; it++) {
					cout << it->second << endl;
				}
				break;
			case 2:
				my_map.erase(key);
				break;
			case 3:
				L = key;
				cin >> R;
				it1 = my_map.lower_bound(L);
				it2 = my_map.upper_bound(R);
				for (it = it1; it != it2; it++) {
					cout << it->first << " " << it->second << endl;
				}
				break;
		}
	}
}
