#include<bits//stdc++.h>
using namespace std;
typedef multimap<string, int>::iterator itr;
int n,i,c,x;
multimap<string, int>S;
int main()
{
    cin >> n;
    for (i = 0; i < n; i++)
    {
        string s,t; cin >> c >> s;
        if (c == 0)
        {
            cin >> x;
            S.insert(make_pair(s, x));
        }
        else if (c == 1)
        {
            itr a = S.lower_bound(s), b = S.upper_bound(s);
            for (itr it = a; it != b; it++)cout << it->second << endl;
        }
        else if (c == 2)S.erase(s);
        else
        {
            cin >> t;
            itr a = S.lower_bound(s), b = S.upper_bound(t);
            for (itr it = a; it != b; it++)cout << it->first << " " << it->second << endl;
        }
    }
}
