#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e3 + 100;
const int XX = 5000;
const long double lg2 = log(2);
const long double lg3 = log(3);
int val[XX];
pair<int, int> add(pair<int, int> a, pair<int, int> b) {
  return {a.first + b.first, a.second + b.second};
}
pair<int, int> sub(pair<int, int> a, pair<int, int> b) {
  return {a.first - b.first, a.second - b.second};
}
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a == b) return true;
  if (a.first > b.first) return !cmp(b, a);
  b.first -= a.first;
  if (a.second < b.second) return false;
  a.second -= b.second;
  return a.second >= val[b.first];
}
int n, a[MAXN][MAXN];
int dp[8][MAXN][MAXN];
int dr[] = {-1, 0, 0, 1, -1, -1, 1, 1};
int dc[] = {0, -1, 1, 0, -1, 1, -1, 1};
bool valid(int r, int c) { return 0 <= r && r < n && 0 <= c && c < n; }
int go(int i, int r, int c) {
  if (!valid(r, c)) return 0;
  if (~dp[i][r][c]) return dp[i][r][c];
  if (a[r][c] == 0) return dp[i][r][c] = 0;
  return dp[i][r][c] = 1 + go(i, r + dr[i], c + dc[i]);
}
pair<int, int> p[8][MAXN][MAXN];
pair<int, int> get(int i, int r, int c) {
  if (!valid(r, c)) return {0, 0};
  if (~p[i][r][c].first) return p[i][r][c];
  pair<int, int> now;
  if (a[r][c] == 2) now.first = 1;
  if (a[r][c] == 3) now.second = 1;
  return p[i][r][c] = add(now, get(i, r - dr[i], c - dc[i]));
}
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < n; j++) {
      a[i][j] = s[j] - '0';
    }
  }
  for (int i = 1; i < XX; i++) {
    int j = 0;
    while (j * lg3 < i * lg2) ++j;
    val[i] = j;
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < 8; i++)
    for (int r = 0; r < n; r++)
      for (int c = 0; c < n; c++) go(i, r, c);
  for (int i = 0; i < 8; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++) p[i][j][k] = {-1, -1};
  pair<int, int> best;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int d = min({dp[0][i][j], dp[1][i][j], dp[2][i][j], dp[3][i][j]}) - 1;
      if (d >= 0) {
        pair<int, int> now;
        now = add(now, get(2, i + d * dr[2], j + d * dc[2]));
        now = sub(now, get(2, i - (d + 1) * dr[2], j - (d + 1) * dc[2]));
        now = add(now, get(3, i + d * dr[3], j + d * dc[3]));
        now = sub(now, get(3, i - (d + 1) * dr[3], j - (d + 1) * dc[3]));
        if (a[i][j] == 2) now.first--;
        if (a[i][j] == 3) now.second--;
        if (cmp(now, best)) best = now;
      }
      d = min({dp[4][i][j], dp[5][i][j], dp[6][i][j], dp[7][i][j]}) - 1;
      if (d >= 0) {
        pair<int, int> now;
        now = add(now, get(6, i + d * dr[6], j + d * dc[6]));
        now = sub(now, get(6, i - (d + 1) * dr[6], j - (d + 1) * dc[6]));
        now = add(now, get(7, i + d * dr[7], j + d * dc[7]));
        now = sub(now, get(7, i - (d + 1) * dr[7], j - (d + 1) * dc[7]));
        if (a[i][j] == 2) now.first--;
        if (a[i][j] == 3) now.second--;
        if (cmp(now, best)) best = now;
      }
    }
  }
  int ans = 1;
  for (int i = 0; i < best.first; i++) ans = 2ll * ans % MOD;
  for (int i = 0; i < best.second; i++) ans = 3ll * ans % MOD;
  if (best.first == 0 && best.second == 0) {
    ans = 0;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (a[i][j]) ans = 1;
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int te = 1;
  for (int w = 1; w <= te; w++) {
    solve();
  }
  return 0;
}
