#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int U[1 << 10][1 << 10];
int D[1 << 10][1 << 10];
int L[1 << 10][1 << 10];
int R[1 << 10][1 << 10];
int D1[1 << 10][1 << 10];
int D2[1 << 10][1 << 10];
int D3[1 << 10][1 << 10];
int D4[1 << 10][1 << 10];
char c[1 << 10][1 << 10];
long double s1[1 << 10][1 << 10];
long double s2[1 << 10][1 << 10];
long double d1[1 << 10][1 << 10];
long double d2[1 << 10][1 << 10];
int main(void) {
  int n;
  ios_base ::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> (c[i] + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) {
      long double val = c[i][j] == '0' ? -70 : log(c[i][j] - '0');
      s1[i][j] = s1[i - 1][j] + val;
      s2[i][j] = s2[i][j - 1] + val;
      d1[i][j] = d1[i - 1][j - 1] + val;
    }
  for (int i = n; i; --i)
    for (int j = 1; j <= n; ++j) {
      long double val = c[i][j] == '0' ? -70 : log(c[i][j] - '0');
      d2[i][j] = d2[i + 1][j - 1] + val;
    }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) {
      U[i][j] = c[i][j] == '0' ? 0 : U[i - 1][j] + 1;
      D1[i][j] = c[i][j] == '0' ? 0 : D1[i - 1][j - 1] + 1;
    }
  for (int i = 1; i <= n; ++i)
    for (int j = n; j; --j) {
      R[i][j] = c[i][j] == '0' ? 0 : R[i][j + 1] + 1;
      D2[i][j] = c[i][j] == '0' ? 0 : D2[i - 1][j + 1] + 1;
    }
  for (int i = n; i; --i)
    for (int j = n; j; --j) {
      D[i][j] = c[i][j] == '0' ? 0 : D[i + 1][j] + 1;
      D3[i][j] = c[i][j] == '0' ? 0 : D3[i + 1][j + 1] + 1;
    }
  for (int i = n; i; --i)
    for (int j = 1; j <= n; ++j) {
      L[i][j] = c[i][j] == '0' ? 0 : L[i][j - 1] + 1;
      D4[i][j] = c[i][j] == '0' ? 0 : D4[i + 1][j - 1] + 1;
    }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      --U[i][j], --D[i][j], --L[i][j], --R[i][j], --D1[i][j], --D2[i][j],
          --D3[i][j], --D4[i][j];
  pair<pair<long double, int>, pair<int, int> > ans = {{-500, 0}, {0, 0}};
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (c[i][j] != '0') {
        int l1 = min({L[i][j], R[i][j], U[i][j], D[i][j]});
        int l2 = min({D1[i][j], D2[i][j], D3[i][j], D4[i][j]});
        ans = max(ans, {{s1[i + l1][j] - s1[i - l1 - 1][j] + s2[i][j + l1] -
                             s2[i][j - l1 - 1] - log(c[i][j] - '0'),
                         0},
                        {i, j}});
        ans = max(ans, {{d1[i + l2][j + l2] - d1[i - l2 - 1][j - l2 - 1] -
                             d2[i + l2 + 1][j - l2 - 1] + d2[i - l2][j + l2] -
                             log(c[i][j] - '0'),
                         1},
                        {i, j}});
      }
  if (ans.first.first <= -50) {
    cout << (0) << '\n';
    exit(0);
  };
  int rs = 1;
  if (!ans.first.second) {
    int a = ans.second.first, b = ans.second.second;
    int l = min({L[a][b], R[a][b], U[a][b], D[a][b]});
    for (int i = 1; i <= l; ++i)
      rs = (rs * 1ll * (c[a - i][b] - '0') * (c[a + i][b] - '0') *
            (c[a][b - i] - '0') * (c[a][b + i] - '0')) %
           mod;
    rs = (1ll * rs * (c[a][b] - '0')) % mod;
    {
      cout << (rs) << '\n';
      exit(0);
    };
  } else {
    int a = ans.second.first, b = ans.second.second;
    int l = min({D1[a][b], D2[a][b], D3[a][b], D4[a][b]});
    for (int i = 1; i <= l; ++i)
      rs = (rs * 1ll * (c[a - i][b - i] - '0') * (c[a - i][b + i] - '0') *
            (c[a + i][b - i] - '0') * (c[a + i][b + i] - '0')) %
           mod;
    rs = (1ll * rs * (c[a][b] - '0')) % mod;
    {
      cout << (rs) << '\n';
      exit(0);
    };
  }
  return 0;
}
