#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
    int q, com, x;
    string key;
    multimap<string, int> M;
    cin >> q;
    
    rep(i, q)
    {
        cin >> com;
        
        if (com == 0)
        {
            cin >> key >> x;
            M.insert(make_pair(key, x));
        }
        else if (com == 1)
        {
            cin >> key;
            map<string, int>::iterator st, en;
            st = M.lower_bound(key);
            en = M.upper_bound(key);
            for(; st != en; st++){
				cout << st->second << endl;
			}
		}
        else if (com == 2)
        {
            cin >> key;
            M.erase(key);
        }
        else
        {
            string L, R;
            cin >> L >> R;
            map<string, int>::iterator st, en;
            st = M.lower_bound(L);
            en = M.upper_bound(R);
            for(; st != en; st++){
				cout << st->first << ' ' << st->second << endl;
			}
        }
    }
}

