#include <bits/stdc++.h>
using namespace std;
int c1, c2, c3, x, y, b2, b3, i, j, k, kk, dy, dx, l,
    M = 1e9 + 7,
    d[][2] = {
        {1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1},
};
array<array<int, 1000>, 1000> f;
array<array<array<uint16_t, 1000>, 1000>, 8> n1s, n2s, n3s;
int main() {
  int n;
  cin >> n;
  bool nz = false;
  for (char c; i < n; ++i)
    for (j = 0; j < n && cin >> c; ++j) nz |= (f[i][j] = c - '0');
  if (!nz) return puts("0");
  auto F = [&](int y, int x, int j) {
    int dy = d[j][0];
    dx = d[j][1];
    y += dy;
    x += dx;
    for (c1 = 0, c2 = 0, c3 = 0; 0 <= y && y < n && 0 <= x && x < n;
         y += dy, x += dx) {
      if (f[y][x] == 0) c1 = c2 = c3 = 0;
      if (f[y][x] == 1) ++c1;
      if (f[y][x] == 2) ++c2;
      if (f[y][x] == 3) ++c3;
      n1s[j][y][x] = c1;
      n2s[j][y][x] = c2;
      n3s[j][y][x] = c3;
    }
  };
  for (i = -1; i <= n; ++i)
    for (j = 0; j < 8; ++j) F(-1, i, j), F(n, i, j), F(i, -1, j), F(i, n, j);
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n; ++j) {
      for (int k : {0, 4}) {
        auto len = [&](int kk) {
          return n1s[k + kk][i][j] + n2s[k + kk][i][j] + n3s[k + kk][i][j];
        };
        l = min({len(0), len(1), len(2), len(3)});
        if (l >= 1) {
          c2 = 0, c3 = 0;
          if (f[i][j] == 2) ++c2;
          if (f[i][j] == 3) ++c3;
          for (kk = 0; kk < 4; ++kk) {
            y = i + (l - 1) * d[k + kk][0];
            x = j + (l - 1) * d[k + kk][1];
            c2 += n2s[k + kk][y][x] - n2s[k + kk][i][j];
            c3 += n3s[k + kk][y][x] - n3s[k + kk][i][j];
          }
          if (b2 * log(2) + b3 * log(3) < c2 * log(2) + c3 * log(3))
            tie(b2, b3) = tie(c2, c3);
        }
      }
    }
  }
  int64_t ans = 1;
  while (b2--) ans = 2 * ans % M;
  while (b3--) ans = 3 * ans % M;
  cout << ans << '\n';
}
