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

public static class Permi
{
    public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> items, int? k = null)
    {
        if (k == null) k = items.Count();
        if (k == 0) yield return Enumerable.Empty<T>();
        else
        {
            var i = 0;
            foreach (var x in items)
            {
                var xs = items.Where((_, index) => i != index);
                foreach (var c in Perm(xs, k - 1))
                    yield return c.Before(x);
                i++;
            }
        }
    }
    public static IEnumerable<T> Before<T>(this IEnumerable<T> items, T first)
    {
        yield return first;
        foreach (var i in items) yield return i;
    }
}

public class hello
{
    public static int ans;
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var s = Console.ReadLine().Trim();
        if (n == 1) { putAns("123456789"); goto exit; }
        var ip = getInputTable(n, s);
        var t = makeTable();
        var a = Enumerable.Range(1, 9).Perm();
        ans = int.MaxValue;
        var anss = new List<string>();

        foreach (var x in a)
        {
            var b = x.ToArray();
            var temp = getNum(b, t, ip);
            if (temp == ans)
            {
                anss.Add(getS(b));
                if (anss.Count() > 1000)
                {
                    anss.Sort();
                    putAns(anss[0]);
                    goto exit;
                }
            }
            else if (temp < ans)
            {
                ans = temp;
                anss.Clear();
                anss.Add(getS(b));
            }
        }
        anss.Sort();
        putAns(anss[0]);
    exit:;
    }
    static int[,] getInputTable(int n, string s)
    {
        var w = new int[10, 10];
        for (int i = 0; i < n - 1; i++)
            w[s[i] - '0', s[i + 1] - '0']++;
        return w;
    }
    static void putAns(string s)
    {
        Console.WriteLine(s.Substring(0, 3));
        Console.WriteLine(s.Substring(3, 3));
        Console.WriteLine(s.Substring(6));
    }
    static string getS(int[] b)
    {
        var res = "";
        for (int i = 0; i < 9; i++)
            res += b[i].ToString();
        return res;
    }
    static int getNum(int[] b, int[,] t, int[,] ip)
    {
        var res = 0;
        var w = new int[10];
        for (int i = 0; i <= 8; i++)
            w[b[i]] = i;
        for (int i = 1; i <= 9; i++)
            for (int j = 1; j <= 9; j++)
            {
                if (ip[i, j] != 0)
                {
                    var from = w[i];
                    var to = w[j];
                    res += t[from, to] * ip[i, j];
                }
            }
        return res;
    }
    static int[,] makeTable()
    {
        var t = new int[9, 9];
        var a = new string[] { "012123234", "001212323", "000321432", "000012123", "000001212", "000000321", "000000012", "000000001" };
        for (int i = 0; i <= 7; i++)
            for (int j = i + 1; j <= 8; j++)
            {
                t[i, j] = a[i][j] - '0';
                t[j, i] = t[i, j];
            }
        return t;
    }
}



Measured memory_bytes: 29100