#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
const double lg2 = log(2), lg3 = log(3);
const long long MOD = 1e9 + 7;
int n, v[MAXN][MAXN];
double logs[MAXN][MAXN], sum[8][MAXN][MAXN];
int cnt[8][MAXN][MAXN];
int dx[8] = {1, 1, -1, -1, -1, 1, 0, 0};
int dy[8] = {1, -1, 1, -1, 0, 0, 1, -1};
inline bool in(int x, int y) { return x >= 0 && x < n && y >= 0 && y < n; }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < n; k++) {
      scanf("%1d", &v[i][k]);
      if (v[i][k] == 2)
        logs[i][k] = lg2;
      else if (v[i][k] == 3)
        logs[i][k] = lg3;
    }
  }
  for (int op = 0; op < 8; op++) {
    int ddx = dx[op];
    int ddy = dy[op];
    for (int i = 0; i < n; i++) {
      for (int k = 0; k < n; k++) {
        if (in(i - ddx, k - ddy)) continue;
        int x = i, y = k, c = 0;
        while (in(x, y)) {
          if (x == i && y == k) {
            sum[op][x][y] = logs[x][y];
            cnt[op][x][y] = 0;
            c = (v[x][y] != 0);
          } else {
            if (v[x][y] != 0) {
              sum[op][x][y] = sum[op][x - ddx][y - ddy] + logs[x][y];
              cnt[op][x][y] = c;
              c++;
            } else {
              c = 0;
              sum[op][x][y] = 0;
              cnt[op][x][y] = c;
            }
          }
          x += ddx;
          y += ddy;
        }
      }
    }
  }
  int ansX = 0, ansY = 0, ansBase = 0, ansSize = 0;
  double ansSum = 0;
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < n; k++) {
      int size[2] = {(int)1e9 + 10, (int)1e9 + 10};
      for (int base = 0; base < 2; base++)
        for (int _op = 0; _op < 4; _op++)
          size[base] = min(size[base], cnt[base * 4 + _op][i][k]);
      for (int base = 0; base < 2; base++) {
        double curSum = logs[i][k];
        for (int _op = 0; _op < 4; _op++) {
          int op = base * 4 + _op;
          int nx = i + dx[op] * (size[base]);
          int ny = k + dy[op] * (size[base]);
          curSum += sum[op][nx][ny] - sum[op][i][k];
        }
        if (curSum >= ansSum) {
          ansSum = curSum;
          ansX = i;
          ansY = k;
          ansBase = base;
          ansSize = size[base];
        }
      }
    }
  }
  long long ans = v[ansX][ansY];
  for (int i = 1; i <= ansSize; i++) {
    for (int _op = 0; _op < 4; _op++) {
      int op = ansBase * 4 + _op;
      ans = (ans * (long long)v[ansX + i * dx[op]][ansY + i * dy[op]]) % MOD;
    }
  }
  printf("%lld\n", ans);
}
