#include <bits/stdc++.h>
using namespace std;
const int N = 2007;
const int M = (int)1e9 + 7;
string s;
int a[N][N];
int aa[N][N];
int b[4][N][N];
int c[4][N][N];
int r2, r3, n;
bool ok(int p, int q, int r) {
  if (p - r >= 1 && p + r <= n && q - r >= 1 && q + r <= n) return true;
  return false;
}
void solve() {
  for (int i = 0; i < 4; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        b[i][j][k] = b[i][j][k - 1] + (a[j][k] == i);
        c[i][j][k] = c[i][j - 1][k] + (a[j][k] == i);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j] != 0 && a[i][j] != -1) {
        int lo = 0, hi = n, md;
        while (hi - lo > 1) {
          md = (lo + hi) >> 1;
          if (!ok(i, j, md) || (b[0][i][j + md] - b[0][i][j - md - 1] > 0) ||
              (c[0][i + md][j] - c[0][i - md - 1][j] > 0))
            hi = md;
          else
            lo = md;
        }
        int c2 = (b[2][i][j + lo] - b[2][i][j - lo - 1]) +
                 (c[2][i + lo][j] - c[2][i - lo - 1][j]);
        int c3 = (b[3][i][j + lo] - b[3][i][j - lo - 1]) +
                 (c[3][i + lo][j] - c[3][i - lo - 1][j]);
        if (a[i][j] == 2) c2--;
        if (a[i][j] == 3) c3--;
        double d1 = log(2.) * r2 + log(3.) * r3;
        double d2 = log(2.) * c2 + log(3.) * c3;
        if (d1 < d2) r2 = c2, r3 = c3;
      }
    }
  }
}
void rotate() {
  int nn = 2 * n - 1;
  for (int i = 1; i <= nn; i++) {
    for (int j = 1; j <= nn; j++) {
      aa[i][j] = -1;
    }
  }
  for (int i = 1, x, y; i <= n; i++) {
    x = i, y = n - i + 1;
    for (int j = 1, k = i; j <= n; j++) {
      aa[x][y] = a[k][j];
      x++, y++;
    }
  }
  for (int i = 1; i <= nn; i++) {
    for (int j = 1; j <= nn; j++) {
      a[i][j] = aa[i][j];
    }
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; i + j <= n; j++) {
      a[i][j] = a[i][nn - j + 1] = a[nn - i + 1][j] =
          a[nn - i + 1][nn - j + 1] = 0;
    }
  }
  n = nn;
}
int main() {
  bool ok = false;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    for (int j = 1; j <= n; j++) {
      a[i][j] = s[j - 1] - '0';
      if (a[i][j]) ok = true;
    }
  }
  solve();
  rotate();
  solve();
  int ans = ok;
  for (int i = 1; i <= r2; i++) ans = ans * 2ll % M;
  for (int i = 1; i <= r3; i++) ans = ans * 3ll % M;
  cout << ans << '\n';
  return 0;
}
