#include <bits/stdc++.h>
using namespace std;
namespace caide {
template <typename C>
int SZ(const C& c) {
  return (int)c.size();
}
template <typename T>
vector<vector<T>> makeVector(int n, int m) {
  return vector<vector<T>>(n, vector<T>(m));
}
}  // namespace caide
namespace caide {
class ModInt {
 public:
  static unsigned long long MOD;

 public:
  ModInt(int val);
  unsigned long long getValue() const;
  ModInt& operator*=(const ModInt& rhs);

 private:
  unsigned long long value;
};
}  // namespace caide
using namespace caide;
class Solution {
 public:
  pair<int, int> solve(const vector<string>& s) {
    const int n = SZ(s);
    auto hsums2 = makeVector<int>(n, n + 1);
    auto vsums2 = makeVector<int>(n, n + 1);
    auto hsums3 = makeVector<int>(n, n + 1);
    auto vsums3 = makeVector<int>(n, n + 1);
    vector<vector<int>> hz(n), vz(n);
    for (int i = 0; i < n; ++i) {
      hz[i].push_back(-1);
      for (int j = 0; j < n; ++j)
        if (s[i][j] == '0') hz[i].push_back(j);
      hz[i].push_back(n);
      vz[i].push_back(-1);
      for (int j = 0; j < n; ++j)
        if (s[j][i] == '0') vz[i].push_back(j);
      vz[i].push_back(n);
      for (int j = 0; j < n; ++j) {
        hsums2[i][j + 1] = hsums2[i][j] + (int)(s[i][j] == '2');
        hsums3[i][j + 1] = hsums3[i][j] + (int)(s[i][j] == '3');
        vsums2[i][j + 1] = vsums2[i][j] + (int)(s[j][i] == '2');
        vsums3[i][j + 1] = vsums3[i][j] + (int)(s[j][i] == '3');
      }
    }
    int p2 = 0, p3 = 0;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
        if (s[i][j] != '0') {
          auto it = lower_bound(std::begin(hz[i]), std::end(hz[i]), j);
          int j1 = *it;
          --it;
          int j0 = *it;
          it = lower_bound(std::begin(vz[j]), std::end(vz[j]), i);
          int i1 = *it;
          --it;
          int i0 = *it;
          int w = min(min(j1 - j, j - j0), min(i1 - i, i - i0));
          j0 = j - w;
          j1 = j + w;
          i0 = i - w;
          i1 = i + w;
          int hn2 = hsums2[i][j1] - hsums2[i][j0 + 1];
          int hn3 = hsums3[i][j1] - hsums3[i][j0 + 1];
          int vn2 = vsums2[j][i1] - vsums2[j][i0 + 1];
          int vn3 = vsums3[j][i1] - vsums3[j][i0 + 1];
          int n2 = hn2 + vn2;
          int n3 = hn3 + vn3;
          if (s[i][j] == '2') --n2;
          if (s[i][j] == '3') --n3;
          if (better(n2, n3, p2, p3)) {
            p2 = n2;
            p3 = n3;
          }
        }
    return make_pair(p2, p3);
  }
  bool better(int n2, int n3, int p2, int p3) {
    return (n2 - p2) * log(2) > (p3 - n3) * log(3);
  }
  bool better(pair<int, int> p1, pair<int, int> p2) {
    return p1 == p2 || better(p1.first, p1.second, p2.first, p2.second);
  }
  void solve(istream& in, ostream& out) {
    int n;
    in >> n;
    vector<string> s(n);
    for (auto& t : s) in >> t;
    bool haveNonZero = false;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
        if (s[i][j] != '0') haveNonZero = true;
    if (!haveNonZero) {
      out << 0 << endl;
      return;
    }
    auto p1 = solve(s);
    pair<int, int> p2, p3;
    {
      vector<string> t(n, string(n, '0'));
      for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
          if ((i + j) % 2 == 0) t[(i + j) / 2][(i - j + n) / 2] = s[i][j];
      p2 = solve(t);
    }
    {
      vector<string> t(n, string(n, '0'));
      for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
          if ((i + j) % 2 == 1) t[(i + j) / 2][(i - j + n) / 2] = s[i][j];
      p3 = solve(t);
    }
    pair<int, int> p;
    if (better(p1, p2) && better(p1, p3))
      p = p1;
    else if (better(p2, p1) && better(p2, p3))
      p = p2;
    else
      p = p3;
    ModInt::MOD = 1000000007ULL;
    ModInt res = 1;
    while (p.first--) res *= 2;
    while (p.second--) res *= 3;
    out << res.getValue() << endl;
  }
};
void solve(istream& in, ostream& out) {
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  istream& in = cin;
  ostream& out = cout;
  solve(in, out);
  return 0;
}
namespace caide {
unsigned long long ModInt::MOD = 0ULL;
static unsigned long long init(long long val, unsigned long long mod) {
  if (val >= 0)
    return (unsigned long long)val % mod;
  else
    return (mod - (unsigned long long)(-val) % mod) % mod;
}
ModInt::ModInt(int val) : value(init(val, MOD)) {}
unsigned long long ModInt::getValue() const { return value; }
ModInt& ModInt::operator*=(const ModInt& that) {
  value = value * that.value % MOD;
  return *this;
}
}  // namespace caide
