#include <bits/stdc++.h>
using namespace std;
const int N = 1101;
const int dx[8] = {0, -1, -1, -1, 0, 1, 1, 1};
const int dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const long long base = 1e9 + 7;
int n, a[N][N];
int dp[N][N][8];
double lg[N][N], s1[N][N], s2[N][N], s3[2 * N][N], s4[2 * N][N], res;
void DP() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 0; k <= 1; k++) {
        if (a[i][j] == 0)
          dp[i][j][k] = 0;
        else
          dp[i][j][k] = dp[i + dx[k]][j + dy[k]][k] + 1;
      }
  for (int i = 1; i <= n; i++)
    for (int j = n; j >= 1; j--)
      for (int k = 2; k <= 3; k++) {
        if (a[i][j] == 0)
          dp[i][j][k] = 0;
        else
          dp[i][j][k] = dp[i + dx[k]][j + dy[k]][k] + 1;
      }
  for (int i = n; i >= 1; i--)
    for (int j = n; j >= 1; j--)
      for (int k = 4; k <= 5; k++) {
        if (a[i][j] == 0)
          dp[i][j][k] = 0;
        else
          dp[i][j][k] = dp[i + dx[k]][j + dy[k]][k] + 1;
      }
  for (int i = n; i >= 1; i--)
    for (int j = 1; j <= n; j++)
      for (int k = 6; k <= 7; k++) {
        if (a[i][j] == 0)
          dp[i][j][k] = 0;
        else
          dp[i][j][k] = dp[i + dx[k]][j + dy[k]][k] + 1;
      }
}
void Init() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) s1[i][j] = s1[i][j - 1] + lg[i][j];
  for (int j = 1; j <= n; j++)
    for (int i = 1; i <= n; i++) s2[j][i] = s2[j][i - 1] + lg[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      s3[i - j + N][i] = s3[i - j + N][i - 1] + lg[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = n; j >= 1; j--) s4[i + j][i] = s4[i + j][i - 1] + lg[i][j];
}
void make() {
  freopen("test.inp", "w", stdout);
  cout << 100 << endl;
  for (int i = 1; i <= 100; i++) {
    for (int j = 1; j <= 100; j++) cout << 1;
    cout << endl;
  }
  fclose(stdout);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      char c;
      cin >> c;
      a[i][j] = c - '0';
      if (a[i][j] != 0)
        lg[i][j] = log(a[i][j]);
      else
        lg[i][j] = -base;
    }
  DP();
  Init();
  res = lg[1][1];
  int cs1 = 1, cs2 = 1, r = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (a[i][j] != 0) {
        int t =
            min(dp[i][j][0], min(dp[i][j][2], min(dp[i][j][4], dp[i][j][6]))) -
            1;
        if (s1[i][j + t] - s1[i][j - t - 1] < 0) continue;
        if (s2[j][i + t] - s2[j][i - t - 1] < 0) continue;
        double d = s1[i][j + t] - s1[i][j - t - 1];
        d += s2[j][i + t] - s2[j][i - t - 1] - lg[i][j];
        if (d > res) {
          res = d;
          cs1 = i;
          cs2 = j;
          r = t;
        }
        t = min(dp[i][j][1], min(dp[i][j][3], min(dp[i][j][5], dp[i][j][7]))) -
            1;
        if (s3[i - j + N][i + t] - s3[i - j + N][i - t - 1] < 0) continue;
        if (s4[i + j][i + t] - s4[i + j][i - t - 1] < 0) continue;
        d = s3[i - j + N][i + t] - s3[i - j + N][i - t - 1];
        d += s4[i + j][i + t] - s4[i + j][i - t - 1] - lg[i][j];
        if (d > res) {
          res = d;
          cs1 = i;
          cs2 = j;
          r = -t;
        }
      }
  long long ans = 1;
  if (r > 0) {
    for (int i = cs1 - r; i <= cs1 + r; i++) ans = (ans * a[i][cs2]) % base;
    for (int j = cs2 - r; j <= cs2 + r; j++)
      if (j != cs2) ans = (ans * a[cs1][j]) % base;
  } else {
    r = -r;
    ans = a[cs1][cs2];
    for (int i = 1; i <= r; i++)
      for (int j = 1; j <= 7; j += 2)
        ans = (ans * a[cs1 - i * dx[j]][cs2 - i * dy[j]]) % base;
  }
  cout << ans;
  return 0;
}
