#include <bits/stdc++.h>
using namespace std;
template <class T, class L>
bool smax(T &x, L y) {
  return x < y ? (x = y, 1) : 0;
}
template <class T, class L>
bool smin(T &x, L y) {
  return y < x ? (x = y, 1) : 0;
}
const int maxn = 1e3 + 17, mod = 1e9 + 7;
const long double Log2 = logl((long double)2), Log3 = logl((long double)3);
const pair<int, int> z(0, 0);
pair<int, int> ans;
int n, l[maxn][maxn], r[maxn][maxn], u[maxn][maxn], d[maxn][maxn],
    lu[maxn][maxn], ru[maxn][maxn], ld[maxn][maxn], rd[maxn][maxn];
pair<int, int> pl[maxn][maxn], pd[maxn][maxn], pu[maxn][maxn], plu[maxn][maxn],
    pld[maxn][maxn];
char c[maxn][maxn];
long double val(const pair<int, int> &x) {
  return x.first * Log2 + x.second * Log3;
}
void upd(const pair<int, int> &x) {
  if (ans.first >= x.first && ans.second >= x.second) return;
  if (ans.first <= x.first && ans.second <= x.second) {
    ans = x;
    return;
  }
  if (val(ans) < val(x)) ans = x;
}
pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {
  return {a.first + b.first, a.second + b.second};
}
pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) {
  return {a.first - b.first, a.second - b.second};
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  bool ok = 0;
  for (int i = 0; i < n; i++) cin >> c[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) ok |= c[i][j] != '0';
  if (!ok) return cout << "0\n", 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      u[i][j] = !j || c[i][j - 1] == '0' ? 0 : u[i][j - 1] + 1;
      l[i][j] = !i || c[i - 1][j] == '0' ? 0 : l[i - 1][j] + 1;
      lu[i][j] = !i || !j || c[i - 1][j - 1] == '0' ? 0 : lu[i - 1][j - 1] + 1;
      pu[i][j] = (i ? pu[i - 1][j] : z) +
                 pair<int, int>(c[i][j] == '2', c[i][j] == '3');
      pl[i][j] = (j ? pl[i][j - 1] : z) +
                 pair<int, int>(c[i][j] == '2', c[i][j] == '3');
      plu[i][j] =
          i && j ? pair<int, int>(plu[i - 1][j - 1].first + (c[i][j] == '2'),
                                  plu[i - 1][j - 1].second + (c[i][j] == '3'))
                 : pair<int, int>((c[i][j] == '2'), (c[i][j] == '3'));
    }
  for (int i = n - 1; ~i; i--)
    for (int j = 0; j < n; j++) {
      d[i][j] = i == n - 1 || c[i + 1][j] == '0' ? 0 : d[i + 1][j] + 1;
      ld[i][j] =
          i == n - 1 || !j || c[i + 1][j - 1] == '0' ? 0 : ld[i + 1][j - 1] + 1;
      pd[i][j] = pair<int, int>(pd[i + 1][j].first + (c[i][j] == '2'),
                                pd[i + 1][j].second + (c[i][j] == '3'));
      pld[i][j] =
          j ? pair<int, int>(pld[i + 1][j - 1].first + (c[i][j] == '2'),
                             pld[i + 1][j - 1].second + (c[i][j] == '3'))
            : pair<int, int>(c[i][j] == '2', c[i][j] == '3');
    }
  for (int i = n - 1; ~i; i--)
    for (int j = n - 1; ~j; j--) {
      r[i][j] = j == n - 1 || c[i][j + 1] == '0' ? 0 : r[i][j + 1] + 1;
      rd[i][j] = i == n - 1 || j == n - 1 || c[i + 1][j + 1] == '0'
                     ? 0
                     : rd[i + 1][j + 1] + 1;
    }
  for (int i = 0; i < n; i++)
    for (int j = n - 1; ~j; j--) {
      ru[i][j] =
          !i || j == n - 1 || c[i - 1][j + 1] == '0' ? 0 : ru[i - 1][j + 1] + 1;
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (c[i][j] != '0') {
        int x = min({l[i][j], r[i][j], d[i][j], u[i][j]});
        pair<int, int> me = pl[i][j + x] - (j - x ? pl[i][j - x - 1] : z) +
                            pu[i + x][j] - (i - x ? pu[i - x - 1][j] : z) -
                            pair<int, int>(c[i][j] == '2', c[i][j] == '3');
        upd(me);
        x = min({ld[i][j], rd[i][j], lu[i][j], ru[i][j]});
        upd(plu[i + x][j + x] -
            (j - x && i - x ? plu[i - x - 1][j - x - 1] : z) +
            pld[i - x][j + x] - (j - x ? pld[i + x + 1][j - x - 1] : z) -
            pair<int, int>(c[i][j] == '2', c[i][j] == '3'));
      }
  int res = 1;
  while (ans.first--) res = (long long)res * 2 % mod;
  while (ans.second--) res = (long long)res * 3 % mod;
  cout << res << '\n';
  return 0;
}
