#include "bits/stdc++.h"
using namespace std;
using long_t = int64_t;

struct Solver {
	Solver() {
		ios::sync_with_stdio( false );
		cout << fixed << setprecision( 10 );
	}

	void solve() {
		multimap<string, int> m;
		int q;
		cin >> q;
		while( q-- ) {
			int op;
			cin >> op;

			if( op == 0 ) {
				string key;
				int x;
				cin >> key >> x;
				m.insert( { key, x } );
			}
			else if( op == 1 ) {
				string key;
				cin >> key;
				auto p = m.equal_range( key );
				for( auto it = p.first; it != p.second; ++it ) {
					cout << it->second << '\n';
				}
			}
			else if( op == 2 ) {
				string key;
				cin >> key;
				m.erase( key );
			}
			else if( op == 3 ) {
				string L, R;
				cin >> L >> R;
				auto i1 = m.lower_bound( L );
				auto i2 = m.upper_bound( R );
				for( ; i1 != i2; ++i1 ) {
					cout << i1->first << ' ' << i1->second << '\n';
				}
			}
		}
	}
};

int main() {
	Solver().solve();
	return 0;
}

