#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
char s[1010][1010];
int a[1010][1010];
vector<int> R[1010], C[1010];
vector<int> Ju[1010 * 2], Bu[1010 * 2];
int f[1010][1010][4], g[1010][1010][4];
int fv[1010][1010][4], gv[1010][1010][4];
void calc(int &a, int &b, int c, int d) {
  if (1.0 * a * log(2) + 1.0 * b * log(3) <
      1.0 * c * log(2) + 1.0 * d * log(3)) {
    a = c;
    b = d;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  int flag = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
    for (int j = 1; j <= n; j++) {
      a[i][j] = s[i][j] - '0';
      if (a[i][j]) flag = 1;
      for (int k = 2; k <= 3; k++) {
        f[i][j][k] = f[i][j - 1][k];
        g[i][j][k] = g[i - 1][j][k];
        fv[i][j][k] = fv[i - 1][j - 1][k];
        gv[i][j][k] = gv[i - 1][j + 1][k];
      }
      f[i][j][a[i][j]]++;
      g[i][j][a[i][j]]++;
      fv[i][j][a[i][j]]++;
      gv[i][j][a[i][j]]++;
    }
  }
  if (!flag) {
    puts("0");
    return 0;
  }
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= n + 1; j++) {
      if (!a[i][j]) {
        R[i].push_back(j);
        C[j].push_back(i);
        Ju[i + n + 1 - j].push_back(j);
        Bu[i + j].push_back(j);
      }
    }
  }
  for (int i = 0; i <= 2 * n + 2; i++) {
    sort(Ju[i].begin(), Ju[i].end());
    sort(Bu[i].begin(), Bu[i].end());
  }
  int x = 0, y = 0, tx = 0, ty = 0, id = 0, sz = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (!a[i][j]) continue;
      id = upper_bound(R[i].begin(), R[i].end(), j) - R[i].begin();
      sz = min(R[i][id] - j, j - R[i][id - 1]);
      id = upper_bound(C[j].begin(), C[j].end(), i) - C[j].begin();
      sz = min(sz, min(C[j][id] - i, i - C[j][id - 1]));
      tx = f[i][j + sz - 1][2] - f[i][j - sz][2] + g[i + sz - 1][j][2] -
           g[i - sz][j][2];
      ty = f[i][j + sz - 1][3] - f[i][j - sz][3] + g[i + sz - 1][j][3] -
           g[i - sz][j][3];
      if (a[i][j] == 2) tx--;
      if (a[i][j] == 3) ty--;
      calc(x, y, tx, ty);
      id = upper_bound(Ju[i + n + 1 - j].begin(), Ju[i + n + 1 - j].end(), j) -
           Ju[i + n + 1 - j].begin();
      sz = min(Ju[i + n + 1 - j][id] - j, j - Ju[i + n + 1 - j][id - 1]);
      id = upper_bound(Bu[i + j].begin(), Bu[i + j].end(), j) -
           Bu[i + j].begin();
      sz = min(sz, min(Bu[i + j][id] - j, j - Bu[i + j][id - 1]));
      tx = fv[i + sz - 1][j + sz - 1][2] - fv[i - sz][j - sz][2] +
           gv[i + sz - 1][j - sz + 1][2] - gv[i - sz][j + sz][2];
      ty = fv[i + sz - 1][j + sz - 1][3] - fv[i - sz][j - sz][3] +
           gv[i + sz - 1][j - sz + 1][3] - gv[i - sz][j + sz][3];
      if (a[i][j] == 2) tx--;
      if (a[i][j] == 3) ty--;
      calc(x, y, tx, ty);
    }
  }
  int ans = 1;
  while (x--) ans = 2 * ans % mod;
  while (y--) ans = 3LL * ans % mod;
  printf("%d\n", ans);
}
