#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
typedef long long ll;
typedef long double ld;


#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll S[1000] = { 0 };
ll N,M,Q;


int main() {
	multimap<string, ll>A;
	cin >> Q;
	rep(i, Q) {
		ll a;
		cin >> a ;
		if (a==0) {
			string key;
			ll x;
			cin >> key >> x;
			A.insert(make_pair(key, x));
		}
		else if(a==1){
			string key;
			cin >> key;
			multimap<string, ll>::iterator j = A.find(key);
			while(j!=A.end()) {
				string tmp = j->first;
				cout << j->second << endl;
				j++;
				if (j==A.end()||tmp != j->first)break;
			}
		}
		else if(a==2){
			string key;
			cin >> key;
			A.erase(key);
		}
		else {
			string key1,key2;
			cin >> key1>>key2;
			for (multimap<string, ll>::iterator j = A.lower_bound(key1); j != A.upper_bound(key2);++j) {
				cout <<j->first<<" "<< j->second << endl;
			}
		}
	}
	return 0;
}
