#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
int dcmp(double x) { return fabs(x) <= eps ? 0 : (x > 0 ? 1 : -1); }
const int mod = 1e9 + 7;
int ksm(int x, int y) {
  int sum = 1;
  for (; y; y >>= 1) {
    if (y & 1) sum = 1LL * sum * x % mod;
    x = 1LL * x * x % mod;
  }
  return sum;
}
pair<int, int> operator+(const pair<int, int>& p1, const pair<int, int>& p2) {
  return make_pair(p1.first + p2.first, p1.second + p2.second);
}
pair<int, int> operator-(const pair<int, int>& p1, const pair<int, int>& p2) {
  return make_pair(p1.first - p2.first, p1.second - p2.second);
}
bool cmp(const pair<int, int>& p1, const pair<int, int>& p2) {
  double x = (double)p1.first * log(2.) + (double)p1.second * log(3.);
  double y = (double)p2.first * log(2.) + (double)p2.second * log(3.);
  return dcmp(x - y) < 0;
}
int l[1005][1005], r[1005][1005], u[1005][1005], d[1005][1005];
pair<int, int> b[1005][1005], c[1005][1005];
int a[1005][1005];
char str[1005][1005];
int n, N = 0;
pair<int, int> stk[5000005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1);
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) a[i][j] = str[i][j] - '0', cnt += a[i][j] == 0;
  if (cnt == n * n)
    printf("0\n");
  else {
    for (int i = 1; i <= n; i++) {
      for (int j = n; j >= 1; j--)
        if (a[i][j] == 0)
          r[i][j] = 0;
        else
          r[i][j] = r[i][j + 1] + 1;
      for (int j = 1; j <= n; j++)
        if (a[i][j] == 0)
          l[i][j] = 0;
        else
          l[i][j] = l[i][j - 1] + 1;
    }
    for (int j = 1; j <= n; j++) {
      for (int i = 1; i <= n; i++)
        if (a[i][j] == 0)
          u[i][j] = 0;
        else
          u[i][j] = u[i - 1][j] + 1;
      for (int i = n; i >= 1; i--)
        if (a[i][j] == 0)
          d[i][j] = 0;
        else
          d[i][j] = d[i + 1][j] + 1;
    }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        pair<int, int> tmp = make_pair(0, 0);
        if (a[i][j] == 2)
          tmp = make_pair(1, 0);
        else if (a[i][j] == 3)
          tmp = make_pair(0, 1);
        b[i][j] = b[i][j - 1] + tmp;
      }
    for (int j = 1; j <= n; j++)
      for (int i = 1; i <= n; i++) {
        pair<int, int> tmp = make_pair(0, 0);
        if (a[i][j] == 2)
          tmp = make_pair(1, 0);
        else if (a[i][j] == 3)
          tmp = make_pair(0, 1);
        c[i][j] = c[i - 1][j] + tmp;
      }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        if (a[i][j] == 0) continue;
        if (i == 3 && j == 3) {
          i++;
          i--;
        }
        int dist = min(min(l[i][j], r[i][j]), min(u[i][j], d[i][j]));
        pair<int, int> tmp = make_pair(0, 0);
        if (a[i][j] == 2)
          tmp = make_pair(1, 0);
        else if (a[i][j] == 3)
          tmp = make_pair(0, 1);
        pair<int, int> ans = b[i][j + dist - 1] - b[i][j - dist];
        ans = ans + c[i + dist - 1][j] - c[i - dist][j];
        ans = ans - tmp;
        stk[++N] = ans;
      }
    memset(r, 0, sizeof(r));
    memset(l, 0, sizeof(l));
    memset(u, 0, sizeof(u));
    memset(d, 0, sizeof(d));
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++)
        if (a[i][j] == 0)
          r[i][j] = 0;
        else
          r[i][j] = r[i - 1][j - 1] + 1;
      for (int j = n; j >= 1; j--)
        if (a[i][j] == 0)
          l[i][j] = 0;
        else
          l[i][j] = l[i - 1][j + 1] + 1;
    }
    for (int i = n; i >= 1; i--) {
      for (int j = 1; j <= n; j++)
        if (a[i][j] == 0)
          u[i][j] = 0;
        else
          u[i][j] = u[i + 1][j - 1] + 1;
      for (int j = n; j >= 1; j--)
        if (a[i][j] == 0)
          d[i][j] = 0;
        else
          d[i][j] = d[i + 1][j + 1] + 1;
    }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        pair<int, int> tmp = make_pair(0, 0);
        if (a[i][j] == 2)
          tmp = make_pair(1, 0);
        else if (a[i][j] == 3)
          tmp = make_pair(0, 1);
        b[i][j] = b[i - 1][j - 1] + tmp;
      }
    for (int i = 1; i <= n; i++)
      for (int j = n; j >= 1; j--) {
        pair<int, int> tmp = make_pair(0, 0);
        if (a[i][j] == 2)
          tmp = make_pair(1, 0);
        else if (a[i][j] == 3)
          tmp = make_pair(0, 1);
        c[i][j] = c[i - 1][j + 1] + tmp;
      }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        if (a[i][j] == 0) continue;
        if (i == 3 && j == 3) {
          i++;
          i--;
        }
        int dist = min(min(l[i][j], r[i][j]), min(u[i][j], d[i][j]));
        pair<int, int> tmp = make_pair(0, 0);
        if (a[i][j] == 2)
          tmp = make_pair(1, 0);
        else if (a[i][j] == 3)
          tmp = make_pair(0, 1);
        pair<int, int> ans =
            b[i + dist - 1][j + dist - 1] - b[i - dist][j - dist];
        ans = ans + c[i + dist - 1][j - dist + 1] - c[i - dist][j + dist];
        ans = ans - tmp;
        stk[++N] = ans;
      }
    sort(stk + 1, stk + 1 + N, cmp);
    int ans = 1;
    ans = 1LL * ksm(2, stk[N].first) * ksm(3, stk[N].second) % mod;
    printf("%d\n", ans);
  }
  return 0;
}
