#include <bits/stdc++.h>

using namespace std;

int main() 
{
    int n, x, z, i;
    string w, y;
    cin >> n;
    
    multimap<string, int> m;
    
    for(i = 0; i < n; i++)
    {
        cin >> x >> y;
        
        if(x == 0)
        {
            cin >> z;
            m.insert(make_pair(y, z));
        }
        else if(x == 1)
        {
            auto it = m.equal_range(y);
            while(it.first != it.second)
            {
                printf("%d\n", it.first->second);
                it.first++;
            }
        }
        else if(x == 2)
        {
            m.erase(y);
        }
        else if(x == 3)
        {
            cin >> w;
            
            auto L = m.lower_bound(y);
            auto R = m.upper_bound(w);
            
            while(L != R)
            {
                printf("%s %d\n", ((*L).first).c_str(), (*L).second);
                L++;
            }
        }
    }
    
    return 0;
}
