#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

#define INF 1<<29

int cnt[9][9];

int calc_dist(const vector<int> &v){
  int ret = 0;
  for(int i=0;i<9;i++){
    for(int j=i+1;j<9;j++){
      int dist_ij = abs(int(i/3) - int(j/3)) + abs(int(i%3) - int(j%3));
      //      cout << v[i] << " " << v[j] << " " << dist_ij << " " << cnt[v[i]-1][v[j]-1] << endl;
      ret += dist_ij * cnt[v[i]-1][v[j]-1];
    }
  }
  return ret;
}

int main(){
  memset(cnt, 0, sizeof(cnt));
  int N;
  string S;
  cin >> N >> S;
  for(int i=1;i<N;i++){
    cnt[S[i-1]-'1'][S[i]-'1']++;
    cnt[S[i]-'1'][S[i-1]-'1']++;
  }

  vector<int> v{1, 2, 3, 4, 5, 6, 7, 8, 9};
  vector<int> ret;
  int best_score = INF;
  do{
    int score = calc_dist(v);
    if(score < best_score){
      //      cout << score << endl;
      best_score = score;
      ret = v;
    }
}while(next_permutation(v.begin(), v.end()));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cout << ret[i*3+j];
    }
    cout << endl;
  }
  return 0;
}

