/**
 *    author:  tourist
 *    created: 25.10.2022 10:30:20       
**/
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

const int md = 998244353;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  long long ans = 1;
  for (int rot = 0; rot < 2; rot++) {
    for (int i = 0; i < n; i++) {
      int beg = 0;
      while (beg < n) {
        if (s[i][beg] != '?') {
          beg += 1;
          continue;
        }
        int end = beg;
        while (end + 1 < n && s[i][end + 1] == '?') {
          end += 1;
        }
        int blacks = 0;
        blacks += (beg > 0 && s[i][beg - 1] == '#');
        blacks += (end < n - 1 && s[i][end + 1] == '#');
        if (blacks == 2) {
          ans = 0;
        }
        if (blacks == 0) {
          ans = ans * (end - beg + 2) % md;
        }
        beg = end + 1;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        swap(s[i][j], s[j][i]);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
