#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e9
#define INFL          static_cast<lint>(INF)
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)     for(lint i=n-1;i>=0;--i)
#define REPR1(i,n)    for(lint i=n;i>0;--i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
int main()
{
	multimap<string, int>m;
	int q = in();
	REP(i, q)
	{
		int n = in();
		string key;
		int x;
		switch (n)
		{
		case 0:
			key = in<string>();
			x = in();
			m.insert(make_pair(key, x));
			break;
		case 1:
			key = in<string>();
			for (auto p = m.equal_range(key); p.first != p.second; p.first++)cout << p.first->second << endl;
			break;
		case 2:
			key = in<string>();
			m.erase(m.equal_range(key).first, m.equal_range(key).second);
			break;
		case 3:
			string l = in<string>(), r = in<string>();
			for (auto itr1 = m.lower_bound(l), itr2 = m.upper_bound(r); itr1 != itr2; itr1++)cout << itr1->first << ' ' << itr1->second << endl;
			break;
		}
	}
}
