#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(vec, s) vec.find(s) != vec.end()

int main() {
	multimap<string, int> MM;
	int q;
	cin >> q;
	Rep(i, q) {
		int n;
		cin >> n;
		if (n == 0) {
			string key;
			int x;
			cin >> key >> x;
			MM.insert(make_pair(key, x));
		}
		else if (n == 1) {
			string key;
			cin >> key;
			for (auto itr = MM.lower_bound(key); itr != MM.end() && itr != MM.upper_bound(key); itr++) {
				cout << get<1>(*itr) << endl;
			}
		}
		else if (n == 2) {
			string key;
			cin >> key;
			MM.erase(key);
		}
		else if (n == 3) {
			string L, R;
			cin >> L >> R;
			for (auto itr = MM.lower_bound(L); itr != MM.end() && itr != MM.upper_bound(R); itr++) {
				cout << get<0>(*itr) << " " << get<1>(*itr) << endl;
			}
		}
	}
	return 0;
}
