#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<long long>;
using vvb = vector<vector<bool>>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vpii = vector<pair<int, int>>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using seti = set<int>;
using useti = unordered_set<int>;
template <typename... ArgTypes>
void print(ArgTypes... args);
template <typename... ArgTypes>
void input(ArgTypes &...args);
template <>
void print() {}
template <>
void input() {}
template <typename T, typename... ArgTypes>
void print(T t, ArgTypes... args) {
  cout << t;
  print(args...);
}
template <typename T, typename... ArgTypes>
void input(T &t, ArgTypes &...args) {
  cin >> t;
  input(args...);
}
class State {
 public:
  int two, three, dis;
  double val;
  State() {
    two = 0;
    three = 0;
    dis = 0;
    val = 0.0;
  }
  State(int k) {
    two = 0;
    three = 0;
    if (k == 2)
      two = 1;
    else if (k == 3)
      three = 1;
    dis = 1;
    val = log2((double)k);
  }
  State(const State &rhs) {
    this->two = rhs.two;
    this->three = rhs.three;
    this->dis = rhs.dis;
    this->val = rhs.val;
  }
  State operator=(const State &rhs) {
    this->two = rhs.two;
    this->three = rhs.three;
    this->dis = rhs.dis;
    this->val = rhs.val;
    return *this;
  }
  bool operator<(const State &rhs) { return this->val < rhs.val; }
  int getVal() {
    int res = 1;
    for (int i = 0; i < two; i++) res = 2LL * res % 1000000007;
    for (int i = 0; i < three; i++) res = 3LL * res % 1000000007;
    return res;
  }
};
State combine(State a, State b) {
  a.dis += b.dis;
  a.val += b.val;
  a.two += b.two;
  a.three += b.three;
  return a;
}
State subtract(State a, State b) {
  a.dis -= b.dis;
  a.val -= b.val;
  a.two -= b.two;
  a.three -= b.three;
  return a;
}
int n;
vvi mat;
vector<vvb> visited;
vector<vector<vector<State>>> memo;
State ans;
int dr[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dc[] = {1, -1, 0, 0, 1, -1, -1, 1};
State dp(int r, int c, int s) {
  if (r < 0 || r >= n || c < 0 || c >= n) return State();
  if (visited[r][c][s]) return memo[r][c][s];
  visited[r][c][s] = 1;
  if (mat[r][c] == 0) return memo[r][c][s] = State();
  State res(mat[r][c]);
  memo[r][c][s] = combine(res, dp(r + dr[s], c + dc[s], s));
  return memo[r][c][s];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  mat = vvi(n, vi(n));
  memo = vector<vector<vector<State>>>(
      n, vector<vector<State>>(n, vector<State>(8, State())));
  visited = vector<vvb>(n, vvb(n, vb(8, 0)));
  int zeros = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      char c;
      cin >> c;
      if (c == '0') zeros++;
      mat[i][j] = c - '0';
    }
  if (zeros == n * n) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (mat[i][j]) {
        State now(mat[i][j]);
        vector<State> temp;
        for (int k = 0; k < 4; k++) temp.push_back(dp(i + dr[k], j + dc[k], k));
        int d = INT32_MAX;
        for (int k = 0; k < 4; k++) d = min(d, temp[k].dis);
        for (int k = 0; k < 4; k++)
          temp[k] = subtract(temp[k],
                             dp(i + (d + 1) * dr[k], j + (d + 1) * dc[k], k));
        State res = now;
        for (int k = 0; k < 4; k++) res = combine(res, temp[k]);
        if (ans < res) ans = res;
        temp.clear();
        for (int k = 0; k < 4; k++)
          temp.push_back(dp(i + dr[k + 4], j + dc[k + 4], k + 4));
        d = INT32_MAX;
        for (int k = 0; k < 4; k++) d = min(d, temp[k].dis);
        for (int k = 0; k < 4; k++)
          temp[k] = subtract(temp[k], dp(i + (d + 1) * dr[k + 4],
                                         j + (d + 1) * dc[k + 4], k + 4));
        res = now;
        for (int k = 0; k < 4; k++) res = combine(res, temp[k]);
        if (ans < res) ans = res;
      }
  cout << ans.getVal() << endl;
}
