#include <bits/stdc++.h>
using namespace std;
const int NN = 1010;
const int mod = 1e9 + 7;
const double eps = 1e-10;
struct triple {
  int len, two, three;
  triple() : len(0), two(0), three(0){};
  triple operator+(triple other) {
    triple _new;
    _new.two = two + other.two;
    _new.three = three + other.three;
    return _new;
  }
  triple operator-(triple other) {
    triple _new;
    _new.two = two - other.two;
    _new.three = three - other.three;
    return _new;
  }
  bool operator<(triple other) {
    double f1 = 1.0 * two * log(2) + 1.0 * three * log(3);
    double f2 = 1.0 * other.two * log(2) + 1.0 * other.three * log(3);
    return f1 < f2;
  }
  void operator=(triple other) {
    len = other.len;
    two = other.two;
    three = other.three;
  }
};
triple L[NN][NN], R[NN][NN], U[NN][NN], D[NN][NN];
triple LU[NN][NN], LD[NN][NN], RU[NN][NN], RD[NN][NN];
triple mx[NN][NN][2];
int a[NN][NN];
int n;
void pre() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (!a[i][j]) continue;
      L[i][j].len = L[i][j - 1].len + 1;
      L[i][j].two = L[i][j - 1].two + (a[i][j] == 2);
      L[i][j].three = L[i][j - 1].three + (a[i][j] == 3);
      U[i][j].len = U[i - 1][j].len + 1;
      U[i][j].two = U[i - 1][j].two + (a[i][j] == 2);
      U[i][j].three = U[i - 1][j].three + (a[i][j] == 3);
      LU[i][j].len = LU[i - 1][j - 1].len + 1;
      LU[i][j].two = LU[i - 1][j - 1].two + (a[i][j] == 2);
      LU[i][j].three = LU[i - 1][j - 1].three + (a[i][j] == 3);
    }
    for (int j = n; j; j--) {
      if (!a[i][j]) continue;
      R[i][j].len = R[i][j + 1].len + 1;
      R[i][j].two = R[i][j + 1].two + (a[i][j] == 2);
      R[i][j].three = R[i][j + 1].three + (a[i][j] == 3);
      RU[i][j].len = RU[i - 1][j + 1].len + 1;
      RU[i][j].two = RU[i - 1][j + 1].two + (a[i][j] == 2);
      RU[i][j].three = RU[i - 1][j + 1].three + (a[i][j] == 3);
    }
  }
  for (int i = n; i; i--) {
    for (int j = 1; j <= n; j++) {
      if (!a[i][j]) continue;
      D[i][j].len = D[i + 1][j].len + 1;
      D[i][j].two = D[i + 1][j].two + (a[i][j] == 2);
      D[i][j].three = D[i + 1][j].three + (a[i][j] == 3);
      LD[i][j].len = LD[i + 1][j - 1].len + 1;
      LD[i][j].two = LD[i + 1][j - 1].two + (a[i][j] == 2);
      LD[i][j].three = LD[i + 1][j - 1].three + (a[i][j] == 3);
    }
    for (int j = n; j; j--) {
      if (!a[i][j]) continue;
      RD[i][j].len = RD[i + 1][j + 1].len + 1;
      RD[i][j].two = RD[i + 1][j + 1].two + (a[i][j] == 2);
      RD[i][j].three = RD[i + 1][j + 1].three + (a[i][j] == 3);
    }
  }
}
triple solve() {
  triple ans;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (!a[i][j]) continue;
      int mn = min({L[i][j].len, R[i][j].len, U[i][j].len, D[i][j].len});
      mx[i][j][0] = mx[i][j][0] + L[i][j] - L[i][j - mn];
      mx[i][j][0] = mx[i][j][0] + R[i][j] - R[i][j + mn];
      mx[i][j][0] = mx[i][j][0] + U[i][j] - U[i - mn][j];
      mx[i][j][0] = mx[i][j][0] + D[i][j] - D[i + mn][j];
      mn = min({LU[i][j].len, LD[i][j].len, RU[i][j].len, RD[i][j].len});
      mx[i][j][1] = mx[i][j][1] + LU[i][j] - LU[i - mn][j - mn];
      mx[i][j][1] = mx[i][j][1] + LD[i][j] - LD[i + mn][j - mn];
      mx[i][j][1] = mx[i][j][1] + RU[i][j] - RU[i - mn][j + mn];
      mx[i][j][1] = mx[i][j][1] + RD[i][j] - RD[i + mn][j + mn];
      if (a[i][j] == 2) mx[i][j][0].two -= 3;
      if (a[i][j] == 2) mx[i][j][1].two -= 3;
      if (a[i][j] == 3) mx[i][j][0].three -= 3;
      if (a[i][j] == 3) mx[i][j][1].three -= 3;
      if (ans < mx[i][j][0]) ans = mx[i][j][0];
      if (ans < mx[i][j][1]) ans = mx[i][j][1];
    }
  }
  return ans;
}
int calc(triple u) {
  int two = u.two;
  int three = u.three;
  int ans = 1;
  for (int i = 0; i < two; i++) ans = 1LL * ans * 2 % mod;
  for (int i = 0; i < three; i++) ans = 1LL * ans * 3 % mod;
  return ans;
}
void Input() {
  cin >> n;
  int flag = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      char c;
      scanf(" %c", &c);
      a[i][j] = c - '0';
      if (a[i][j]) flag = 0;
    }
  }
  if (flag) {
    puts("0");
    exit(0);
  }
}
void Debug() {
  cerr << "Debug!\n";
  cerr << "-------- Input ---------\n";
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cerr << a[i][j] << " ";
    }
    cerr << endl;
  }
  cerr << "-------- pre ----------\n";
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cerr << LU[i][j].three << " ";
    }
    cerr << endl;
  }
  cerr << "-------- solve --------\n";
  triple ans = solve();
  cerr << ans.two << " " << ans.three << endl;
}
int main() {
  Input();
  pre();
  cout << calc(solve());
  return 0;
}
