#include <bits/stdc++.h>
using namespace std;
const long long p = 1000000007;
long long inv[4];
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, -1, -1, -1, 0, 1, 1, 1};
int fk[][2] = {{6, 7}, {0, 1}, {4, 5}, {2, 3}};
int fuck[][4] = {{0, 2, 4, 6}, {1, 3, 5, 7}};
char s[1010][1010];
int ma[8][1010][1010];
pair<int, int> num[8][1010][1010];
void deal(int, int, int);
void get(int *, int *, int, int, int);
bool cmp(int, int, int, int);
bool cmp2(int, int);
long long pow_mod(long long, long long, long long);
int main() {
  int n;
  int a, b, c, d, x, y, xx;
  int dir;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) deal(0, i, j);
    for (int j = n; j; --j) deal(1, i, j);
  }
  for (int i = n; i; --i) {
    for (int j = 1; j <= n; ++j) deal(2, i, j);
    for (int j = n; j; --j) deal(3, i, j);
  }
  xx = x = y = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) {
      if (s[i][j] == '0') continue;
      get(&a, &b, i, j, 0);
      get(&c, &d, i, j, 1);
      if (!cmp(a, b, c, d)) {
        a = c;
        b = d;
      }
      if (cmp(a, b, x, y)) {
        x = a;
        y = b;
        xx = 1;
      }
    }
  printf("%lld", xx * pow_mod(2, x, p) * pow_mod(3, y, p) % p);
  return 0;
}
void deal(int dd, int i, int j) {
  int x = s[i][j] - '0', dir;
  for (int k = 0; k < 2; ++k) {
    dir = fk[dd][k];
    if (x == 0) {
      ma[dir][i][j] = 0;
      num[dir][i][j] = num[dir][i - dx[dir]][j - dy[dir]];
      continue;
    }
    ma[dir][i][j] = ma[dir][i - dx[dir]][j - dy[dir]] + 1;
    num[dir][i][j] = num[dir][i - dx[dir]][j - dy[dir]];
    if (x == 2)
      ++num[dir][i][j].first;
    else if (x == 3)
      ++num[dir][i][j].second;
  }
}
void get(int *a, int *b, int x, int y, int tp) {
  int xx = 0x3f3f3f3f, xxx = s[x][y] - '0';
  int dir;
  *a = *b = 0;
  for (int i = 0; i < 4; ++i) xx = min(xx, ma[fuck[tp][i]][x][y]);
  if (xx == 0) return;
  for (int i = 0; i < 4; ++i) {
    dir = fuck[tp][i];
    *a += num[dir][x][y].first -
          num[dir][x - xx * dx[dir]][y - xx * dy[dir]].first;
    *b += num[dir][x][y].second -
          num[dir][x - xx * dx[dir]][y - xx * dy[dir]].second;
  }
  if (xxx == 2)
    *a -= 3;
  else if (xxx == 3)
    *b -= 3;
}
bool cmp2(int x, int y) { return x * log(2) > y * log(3); }
bool cmp(int x, int y, int u, int v) {
  if (x >= u) {
    if (y >= v) return true;
    x -= u;
    v -= y;
    return cmp2(x, v);
  }
  if (y < v) return false;
  u -= x;
  y -= v;
  return !cmp2(u, y);
}
long long pow_mod(long long x, long long y, long long p) {
  long long res = 1;
  while (y) {
    if (y & 1) {
      res *= x;
      res %= p;
    }
    x *= x;
    x %= p;
    y >>= 1;
  }
  return res;
}
