#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16777216")
using namespace std;
const int INF = 1000000000;
const int MAX = 128;
const int MAX2 = 61;
const int BASE = 1000000000;
int n, m;
int A[MAX];
vector<pair<int, int> > AA;
int M[MAX];
int E[MAX];
int R[MAX][1 << 17];
pair<int, int> Q[MAX][1 << 17];
vector<int> P;
bool Prime(int x) {
  for (int i = 2; i < x; ++i)
    if (x % i == 0) return 0;
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) {
    scanf("%d", &A[i]);
    AA.push_back(make_pair(A[i], i));
  }
  sort(AA.begin(), AA.end());
  sort(A, A + n);
  reverse(A, A + n);
  for (int i = (2); i < (MAX2); ++i)
    if (Prime(i)) P.push_back(i);
  m = (int)P.size();
  for (int i = (1); i < (MAX2); ++i) {
    for (int j = (0); j < (m); ++j)
      if (i % P[j] == 0) M[i] |= (1 << j);
  }
  for (int i = (0); i < (MAX); ++i)
    for (int j = (0); j < ((1 << m)); ++j) {
      R[i][j] = INF;
      Q[i][j] = make_pair(-1, -1);
    }
  R[0][0] = 0;
  int cnt = 0;
  for (int i = (0); i < (n); ++i)
    for (int mask = (0); mask < ((1 << m)); ++mask) {
      if (R[i][mask] == INF) continue;
      int up = MAX2;
      if (i > m + 1) up = 2;
      for (int j = (1); j < (up); ++j) {
        if ((mask & M[j]) == 0)
          if (R[i][mask] + abs(j - A[i]) < R[i + 1][mask | M[j]]) {
            R[i + 1][mask | M[j]] = R[i][mask] + abs(j - A[i]);
            Q[i + 1][mask | M[j]] = make_pair(mask, j);
          }
      }
    }
  vector<int> Res;
  int res = INF;
  int mask = 0;
  for (int i = (0); i < ((1 << m)); ++i)
    if (R[n][i] < res) {
      res = R[n][i];
      mask = i;
    }
  int pos = n;
  while (pos > 0) {
    pair<int, int> p = Q[pos][mask];
    Res.push_back(p.second);
    pos = pos - 1;
    mask = p.first;
  }
  for (int i = (0); i < ((int)Res.size()); ++i) E[AA[i].second] = Res[i];
  for (int i = (0); i < (n); ++i) printf("%d%c", E[i], i + 1 == n ? '\n' : ' ');
  return 0;
}
