#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    multimap<string, int> s;
    int q, a, b;
    string key, key2;
    cin >> q;
    rep(i, q) {
        cin >> a >> key;
        if(a == 0) {
            cin >> b;
            s.insert(make_pair(key, b));
        } else if(a == 1) {
            if(s.find(key) != s.end()) {
                auto p = s.equal_range(key);
                while(p.first != p.second) {
                    cout << p.first->second << "\n";
                    p.first++;
                }
            }
        } else if(a == 2) {
            s.erase(key);
        } else {
            cin >> key2;
            auto p1 = s.lower_bound(key);
            auto p2 = s.upper_bound(key2);
            while(p1 != p2) {
                cout << p1->first << " " << p1->second << "\n";
                p1++;
            }
        }
    }
}
