#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q;
    cin >> q;
    multimap<string, int> mp;
    for(int i = 0; i < q; i++)
    {
        int com, x;
        string key;
        cin >> com;
        if(com == 0)
        {
            cin >> key >> x;
            mp.insert(make_pair(key, x));
        }
        else if(com == 1)
        {
            cin >> key;
            auto itr = mp.equal_range(key);
            for(auto it = itr.first; it != itr.second; it++) cout << it->second << endl;
        }
        else if(com == 2)
        {
            cin >> key;
            mp.erase(key);
        }
        if(com == 3)
        {
            string l, r;
            cin >> l >> r;
            auto left = mp.lower_bound(l);
            auto right = mp.upper_bound(r);
            while(left != right)
            {
                cout << left->first << " " << left->second << endl;
                left++;
            }
        }
    }
    return 0;
}


