#include <bits/stdc++.h>

using namespace std;

int main() {
    multimap<string, int> mmp;

    int q;
    cin >> q;
    while (q--) {
        int op;
        string key;
        cin >> op;
        if (op == 0) {
            int x;
            cin >> key >> x;
            mmp.insert(make_pair(key, x));
        } else if (op == 1) {
            cin >> key;
            for (auto it = mmp.lower_bound(key); it != mmp.upper_bound(key); ++it) {
                cout << it->second << endl;
            }
        } else if (op == 2) {
            cin >> key;
            mmp.erase(key);
        } else {
            string l, r;
            cin >> l >> r;
            for (auto it = mmp.lower_bound(l); it != mmp.upper_bound(r); ++it) {
                cout << it->first << " " << it->second << endl;
            }
        }
    }
    return 0;
}
