#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {
    multimap<string, int> m;
    int q; cin >> q;
    while (q--) {
        int com; cin >> com;
        if (com == 0) {
            string key; int x;
            cin >> key >> x;
            m.emplace(key, x);
        } else if (com == 1) {
            string key; cin >> key;
            auto p = m.equal_range(key);
            for (auto it = p.first; it != p.second; it++) {
                cout << it->second << endl;
            }
        } else if (com == 2) {
            string key; cin >> key;
            m.erase(key);
        } else if (com == 3) {
            string l, r; cin >> l >> r;
            auto it = m.lower_bound(l);
            while (it != m.end() && it->first <= r) {
                cout << it->first << " " << it->second << endl;
                ++it;
            }
        }
    }
    return 0;
}
