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

int main(){
	int n;
	scanf("%d", &n);
	multimap<string, int> s;
	for(int i = 0; i < n; i++) {
		int id;
		scanf("%d", &id);
		string key;
		cin >> key;
		if(id == 0) {
			int x;
			scanf("%d", &x);
			s.emplace(key, x);
		}else if(id == 1) {
			auto itr = s.find(key);
			for(; itr != s.end() && (*itr).first == key; itr++)
				printf("%d\n", (*itr).second);
		}else if(id == 2) {
			s.erase(key);
		}else if(id == 3) {
			string y;
			cin >> y;
			auto itr = s.lower_bound(key);
			for(; itr != s.end() && (*itr).first <= y; itr++)
				cout << (*itr).first << " " << (*itr).second << '\n';
		}
	}
}

