using System.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var d = new Dictionary<string, List<int>>();
        var q = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < q; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var c = int.Parse(line[0]);
            var c2 = line[1];
            if (c == 0)
            {
                var c3 = int.Parse(line[2]);
                if (d.ContainsKey(c2)) d[c2].Add(c3);
                else  d[c2] = new List<int>() { c3 }; 
           }
            else if (c == 1)
            {
                if (d.ContainsKey(c2))
                foreach (var x in d[c2])
                    Console.WriteLine(x);
            }
            else if (c == 2)
            {
                if (d.ContainsKey(c2)) d.Remove(c2);
            }
            else
            {
                var c3 = line[2];
                foreach (var x in d.Where(y => y.Key.CompareTo(c2) >= 0 && y.Key.CompareTo(c3) <= 0).OrderBy(y => y.Key))
                    foreach (var y in x.Value)
                    Console.WriteLine("{0} {1}", x.Key, y);
            }
        }
    }
}

