/*
	@coder: Yeshayah
	@problem: 
*/
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int tc, op, v;
	string k, a, b;
	map<string, vector<int>> mapa;
	cin >> tc;
	while (tc--) {
		cin >> op;
		if (op > 2) {
			cin >> a >> b;
			map<string, vector<int>>::iterator it = mapa.lower_bound(a);
			for (; it != mapa.end() && it -> first <= b; it++)
				for (int i : it -> second)
					cout << it -> first << " " << i << "\n";
		} else {
			cin >> k;
			if (!op) {
				cin >> v;
				mapa[k].push_back(v);
			} else if (op < 2) {
				if (mapa.find(k) != mapa.end()) {
					for (int i : mapa[k])
						cout << i << "\n";
				}
			} else mapa.erase(k);
		}
	}
	return 0;
}
