#include <bits/stdc++.h>
using namespace std;
long long t = 1;
const long long N = 1005;
long double lg32 = log2(3);
inline long long mult(long long x, long long y) {
  return (1LL * x * y) % (long long)1000000007;
}
inline long long powMod(long long base, long long expo) {
  long long ans = 1;
  while (expo) {
    if (expo & 1) ans = mult(ans, base);
    expo >>= 1;
    base = mult(base, base);
  }
  return ans;
}
long long cnt2[8][N][N], cnt3[8][N][N], a[N][N], nonzero[8][N][N];
void go(long long& p2, long long& p3, long long& x, long long& y) {
  if ((p2 - x) * (p3 - y) >= 0) {
    p2 = max(x, p2);
    p3 = max(y, p3);
  } else {
    if (p2 > x) {
      long double X = p2 - x;
      long double Y = y - p3;
      if (X < lg32 * Y) {
        p2 = x;
        p3 = y;
      }
    } else {
      long double X = x - p2;
      long double Y = p3 - y;
      if (X > lg32 * Y) {
        p2 = x;
        p3 = y;
      }
    }
  }
}
void solve() {
  memset(cnt2, 0, sizeof cnt2);
  memset(cnt3, 0, sizeof cnt3);
  memset(nonzero, 0, sizeof nonzero);
  memset(a, 0, sizeof a);
  long long n;
  cin >> n;
  char c;
  for (long long i = 1; i < n + 1; i += 1) {
    for (long long j = 1; j < n + 1; j += 1) {
      cin >> c;
      a[i][j] = (c - '0');
      cnt2[0][i][j] = cnt2[0][i - 1][j] + (a[i][j] == 2);
      cnt2[1][i][j] = cnt2[1][i][j - 1] + (a[i][j] == 2);
      cnt2[2][i][j] = cnt2[2][i - 1][j - 1] + (a[i][j] == 2);
      cnt3[0][i][j] = cnt3[0][i - 1][j] + (a[i][j] == 3);
      cnt3[1][i][j] = cnt3[1][i][j - 1] + (a[i][j] == 3);
      cnt3[2][i][j] = cnt3[2][i - 1][j - 1] + (a[i][j] == 3);
      nonzero[0][i][j] = (a[i][j] == 0 ? 0 : nonzero[0][i - 1][j] + 1);
      nonzero[1][i][j] = (a[i][j] == 0 ? 0 : nonzero[1][i][j - 1] + 1);
      nonzero[2][i][j] = (a[i][j] == 0 ? 0 : nonzero[2][i - 1][j - 1] + 1);
    }
  }
  for (long long i = n; i >= 1; i--) {
    for (long long j = n; j >= 1; j--) {
      cnt2[3][i][j] = cnt2[3][i + 1][j] + (a[i][j] == 2);
      cnt2[4][i][j] = cnt2[4][i][j + 1] + (a[i][j] == 2);
      cnt2[5][i][j] = cnt2[5][i + 1][j + 1] + (a[i][j] == 2);
      cnt3[3][i][j] = cnt3[3][i + 1][j] + (a[i][j] == 3);
      cnt3[4][i][j] = cnt3[4][i][j + 1] + (a[i][j] == 3);
      cnt3[5][i][j] = cnt3[5][i + 1][j + 1] + (a[i][j] == 3);
      nonzero[3][i][j] = (a[i][j] == 0 ? 0 : nonzero[3][i + 1][j] + 1);
      nonzero[4][i][j] = (a[i][j] == 0 ? 0 : nonzero[4][i][j + 1] + 1);
      nonzero[5][i][j] = (a[i][j] == 0 ? 0 : nonzero[5][i + 1][j + 1] + 1);
    }
  }
  for (long long i = 1; i < n + 1; i += 1) {
    for (long long j = n; j >= 1; j--) {
      cnt2[6][i][j] = cnt2[6][i - 1][j + 1] + (a[i][j] == 2);
      cnt3[6][i][j] = cnt3[6][i - 1][j + 1] + (a[i][j] == 3);
      nonzero[6][i][j] = (a[i][j] == 0 ? 0 : nonzero[6][i - 1][j + 1] + 1);
    }
  }
  for (long long i = n; i >= 1; i--) {
    for (long long j = 1; j < n + 1; j += 1) {
      cnt2[7][i][j] = cnt2[7][i + 1][j - 1] + (a[i][j] == 2);
      cnt3[7][i][j] = cnt3[7][i + 1][j - 1] + (a[i][j] == 3);
      nonzero[7][i][j] = (a[i][j] == 0 ? 0 : nonzero[7][i + 1][j - 1] + 1);
    }
  }
  long long p2 = 0, d, x, y, f = 0, p3 = 0;
  for (long long i = 1; i < n + 1; i += 1) {
    for (long long j = 1; j < n + 1; j += 1) {
      if (a[i][j] != 0) f = 1;
      d = min(nonzero[0][i][j],
              min(nonzero[1][i][j], min(nonzero[3][i][j], nonzero[4][i][j])));
      x = 0;
      y = 0;
      x += cnt2[0][i + d - 1][j] - cnt2[0][i - d][j];
      x += cnt2[1][i][j + d - 1] - cnt2[1][i][j - d];
      y += cnt3[0][i + d - 1][j] - cnt3[0][i - d][j];
      y += cnt3[1][i][j + d - 1] - cnt3[1][i][j - d];
      if (a[i][j] == 2) x--;
      if (a[i][j] == 3) y--;
      go(p2, p3, x, y);
      x = 0;
      y = 0;
      d = min(nonzero[2][i][j],
              min(nonzero[5][i][j], min(nonzero[6][i][j], nonzero[7][i][j])));
      x += cnt2[2][i + d - 1][j + d - 1] - cnt2[2][i - d][j - d];
      x += cnt2[7][i - d + 1][j + d - 1] - cnt2[7][i + d][j - d];
      y += cnt3[2][i + d - 1][j + d - 1] - cnt3[2][i - d][j - d];
      y += cnt3[7][i - d + 1][j + d - 1] - cnt3[7][i + d][j - d];
      if (a[i][j] == 2) x--;
      if (a[i][j] == 3) y--;
      go(p2, p3, x, y);
    }
  }
  cout << mult(f, mult(powMod(2, p2), powMod(3, p3)));
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  while (t--) {
    solve();
  }
  return 0;
}
