#include<map>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int T;
    cin >> T;
    multimap<string, int> mp;
    while (T--) {
        int t;
        cin >> t;
        if (t==0) {
            string s;int a;
            cin >> s >> a;
            mp.insert(pair<string ,int >(s, a));
        } else if (t==1) {
            string s;
            cin >> s;
            auto it1 = mp.lower_bound(s);
            auto it2 = mp.upper_bound(s);
            while (it1 != it2) {
                cout << it1->second << endl;
                it1++;
            }
        } else if (t==2) {
            string s;
            cin >> s;
            mp.erase(s);
        } else {
            string l, r;
            cin >> l >> r;
            auto it = mp.lower_bound(l);
            auto it1 = mp.upper_bound(r);
            for (; it !=it1; it++) cout << it->first << " " << it->second <<endl;
        }
    }
    return 0;
}
