// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

void dump_vec(vector<int> vec) {
    for(int i=0; i<3; i++) {
        for(int j=0; j<3; j++) {
            fprintf(stderr, "%lld ", vec[i * 3 + j]);
        }
        fprintf(stderr, "\n");
    }
}

int move_num[15][15], wf[15][15];
signed main() {
    int N; cin >> N;
    string s; cin >> s;

    fill(wf[0], wf[10], INF);
    for(int i=0; i<9; i++) wf[i][i] = 0;
    for(int i=0; i<3; i++) {
        for(int j=0; j<3; j++) {
            int u = i * 3 + j;
            for(int k=0; k<4; k++) {
                int ni = i + dx[k], nj = j + dy[k];
                if(ni < 0 or ni >= 3 or nj < 0 or nj >= 3) continue;
                int v = ni * 3 + nj;
                wf[u][v] = wf[v][u] = 1;
            }
        }
    }

    const int S = 9;
    for(int k=0; k<S; k++) {
        for(int i=0; i<S; i++) {
            for(int j=0; j<S; j++) {
                wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);
            }
        }
    }
    
    /*
    for(int i=0; i<S; i++) {
        for(int j=0; j<S; j++) {
            fprintf(stderr, "wf[%lld][%lld] = %lld\n", i, j, wf[i][j]);
        }
    }
    */

    vector<int> nums;
    for(int i=0; i<N; i++) {
        int num = s[i] - '1';
        nums.push_back(num);
    }

    for(int i=1; i<N; i++) {
        int u = nums[i-1], v = nums[i];
        move_num[u][v]++;
    }

    vector<int> perm(9);
    vector<int> ans(9, INF);
    int mi = INF;
    iota(perm.begin(), perm.end(), 0);
    do {
        vector<int> val2idx(S);
        for(int i=0; i<S; i++) {
            val2idx[ perm[i] ] = i;
        }

        int sum = 0;
        for(int i=0; i<S; i++) {
            for(int j=0; j<S; j++) {
                sum += move_num[i][j] * wf[ val2idx[i] ][ val2idx[j] ];
                if(sum > mi) i = S, j = S;
            }
        }

        if(mi > sum) {
            // fprintf(stderr, "sum = %lld\n", sum);
            // dump_vec(perm);
            mi = sum;
            ans = perm;
        }
        else if(mi == sum) {
            ans = min(ans, perm);
        }
        
    }while(next_permutation(perm.begin(), perm.end()));

    for(int i=0; i<3; i++) {
        for(int j=0; j<3; j++) {
            cout << ans[i * 3 + j] + 1;
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 4112