#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void rt(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    rt(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
const int maxn = 1005, p = 1000000007;
int n, a[maxn][maxn];
char s[maxn];
int mln[maxn][maxn], mlr[maxn][maxn], t[maxn][maxn];
int num[4][3][maxn][maxn];
int qpow(int a, int b) {
  int ret = 1;
  for (; b; b >>= 1, a = (long long)a * a % p)
    if (b & 1) ret = (long long)ret * a % p;
  return ret;
}
int main() {
  n = rd();
  for (int i = 1; i <= (int)(n); i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= (int)(n); j++) a[i][j] = s[j] - '0';
  }
  memset(mln, 60, sizeof mln);
  for (int i = 1, mn = 0; i <= n; i++, mn = 0)
    for (int j = 1; j <= (int)(n); j++) {
      mn += a[i][j] ? 1 : -mn;
      mln[i][j] = min(mln[i][j], mn);
    };
  for (int i = 1, mn = 0; i <= n; i++, mn = 0)
    for (int j = n; j >= (int)(1); j--) {
      mn += a[i][j] ? 1 : -mn;
      mln[i][j] = min(mln[i][j], mn);
    };
  for (int j = 1, mn = 0; j <= n; j++, mn = 0)
    for (int i = 1; i <= (int)(n); i++) {
      mn += a[i][j] ? 1 : -mn;
      mln[i][j] = min(mln[i][j], mn);
    };
  for (int j = 1, mn = 0; j <= n; j++, mn = 0)
    for (int i = n; i >= (int)(1); i--) {
      mn += a[i][j] ? 1 : -mn;
      mln[i][j] = min(mln[i][j], mn);
    };
  memset(mlr, 60, sizeof mlr);
  for (int i = 1; i <= (int)(n); i++)
    for (int j = 1; j <= (int)(n); j++) {
      t[i][j] = a[i][j] ? t[i + -1][j + -1] + 1 : 0,
      mlr[i][j] = min(mlr[i][j], t[i][j]);
    };
  for (int i = 1; i <= (int)(n); i++)
    for (int j = n; j >= (int)(1); j--) {
      t[i][j] = a[i][j] ? t[i + -1][j + 1] + 1 : 0,
      mlr[i][j] = min(mlr[i][j], t[i][j]);
    };
  for (int i = n; i >= (int)(1); i--)
    for (int j = 1; j <= (int)(n); j++) {
      t[i][j] = a[i][j] ? t[i + 1][j + -1] + 1 : 0,
      mlr[i][j] = min(mlr[i][j], t[i][j]);
    };
  for (int i = n; i >= (int)(1); i--)
    for (int j = n; j >= (int)(1); j--) {
      t[i][j] = a[i][j] ? t[i + 1][j + 1] + 1 : 0,
      mlr[i][j] = min(mlr[i][j], t[i][j]);
    };
  for (int i = 1; i <= (int)(n); i++)
    for (int j = 1; j <= (int)(n); j++) {
      {
        for (int p = 1; p <= (int)(3); p++)
          num[0][p - 1][i][j] = num[0][p - 1][i + 0][j + -1] + (a[i][j] == p);
      };
      {
        for (int p = 1; p <= (int)(3); p++)
          num[1][p - 1][i][j] = num[1][p - 1][i + -1][j + 0] + (a[i][j] == p);
      };
      {
        for (int p = 1; p <= (int)(3); p++)
          num[2][p - 1][i][j] = num[2][p - 1][i + -1][j + -1] + (a[i][j] == p);
      };
      {
        for (int p = 1; p <= (int)(3); p++)
          num[3][p - 1][i][j] = num[3][p - 1][i + -1][j + 1] + (a[i][j] == p);
      };
    }
  int n3 = 0, n2 = 0, fd = 0;
  for (int i = 1; i <= (int)(n); i++)
    for (int j = 1; j <= (int)(n); j++)
      if (a[i][j]) {
        fd = 1;
        int t = mln[i][j], t3, t2;
        t3 = num[0][2][i][j + t - 1] - num[0][2][i][j - t] +
             num[1][2][i + t - 1][j] - num[1][2][i - t][j] - (a[i][j] == 3);
        t2 = num[0][1][i][j + t - 1] - num[0][1][i][j - t] +
             num[1][1][i + t - 1][j] - num[1][1][i - t][j] - (a[i][j] == 2);
        if (log(3) * t3 + log(2) * t2 > log(3) * n3 + log(2) * n2)
          n3 = t3, n2 = t2;
        t = mlr[i][j];
        t3 = num[2][2][i + t - 1][j + t - 1] - num[2][2][i - t][j - t] +
             num[3][2][i + t - 1][j - t + 1] - num[3][2][i - t][j + t] -
             (a[i][j] == 3);
        t2 = num[2][1][i + t - 1][j + t - 1] - num[2][1][i - t][j - t] +
             num[3][1][i + t - 1][j - t + 1] - num[3][1][i - t][j + t] -
             (a[i][j] == 2);
        if (log(3) * t3 + log(2) * t2 > log(3) * n3 + log(2) * n2)
          n3 = t3, n2 = t2;
      }
  rt(fd ? (long long)qpow(3, n3) * qpow(2, n2) % p : 0), putchar('\n');
}
