#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



multimap<string,int> MAP;

int main(){

	int num_query;
	scanf("%d",&num_query);

	int command,x;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&command);

		string key;

		if(command == 0){

			cin >> key >> x;
			MAP.insert(make_pair(key,x));

		}else if(command == 1){

			cin >> key;
			auto at = MAP.lower_bound(key);

			while(at != MAP.end() && at->first == key){

				printf("%d\n",at->second);
				at++;
			}

		}else if(command == 2){

			cin >> key;
			MAP.erase(key);

		}else{ //command == 3

			string L,R;

			cin >> L >> R;

			auto at_L = MAP.lower_bound(L);
			auto at_R = MAP.upper_bound(R);

			while(at_L != at_R){

				printf("%s %d\n",at_L->first.c_str(),at_L->second);
				at_L++;
			}
		}
	}

	return 0;
}

