#include <bits/stdc++.h>
inline long long rd() {
  long long _x = 0;
  int _ch = getchar(), _f = 1;
  for (; !isdigit(_ch) && (_ch != '-') && (_ch != EOF); _ch = getchar())
    ;
  if (_ch == '-') {
    _f = 0;
    _ch = getchar();
  }
  for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - '0';
  return _f ? _x : -_x;
}
void write(long long _x) {
  if (_x >= 10)
    write(_x / 10), putchar(_x % 10 + '0');
  else
    putchar(_x + '0');
}
inline void wrt(long long _x, char _p) {
  if (_x < 0) putchar('-'), _x = -_x;
  write(_x);
  if (_p) putchar(_p);
}
int mod;
int n, m;
char str[505][505];
inline int id(int x, int y) { return (x - 1) * (m + 1) + y; }
int f[505 * 505];
int col[505 * 505];
inline int find(int x) { return f[x] == x ? f[x] : f[x] = find(f[x]); }
bool tag[2];
inline void add(int u, int v) {
  if (find(u) == find(v)) tag[col[u]] = 1;
  f[find(u)] = f[find(v)];
}
int s[2], w[505 * 505];
int S, totb, totw;
int mt[2][505][505];
inline void ADD(int c, int x, int y) {
  mt[c][x][y]--;
  mt[c][y][x]--;
  mt[c][x][x]++;
  mt[c][y][y]++;
}
inline int qpow(int x, int k) {
  int ans = 1;
  for (; k; k >>= 1, x = 1ll * x * x % mod)
    if (k & 1) ans = 1ll * ans * x % mod;
  return ans;
}
int solve(int mt[505][505], int sum) {
  sum--;
  int ans = 1;
  int dv = 1;
  for (int i = 1; i <= sum; i++) {
    for (int j = 1; j <= sum; j++) {
      mt[i][j] = (mt[i][j] % mod + mod) % mod;
    }
  }
  for (int i = 1, j = 1; i <= sum && j <= sum; i++, j++) {
    int id = i;
    for (int k = i; k <= sum; k++) {
      if (mt[k][j] != 0) {
        id = k;
        break;
      }
    }
    if (mt[id][j] == 0) {
      i--;
      return 0;
    }
    if (id != i) {
      ans = 1ll * ans * (mod - 1) % mod;
      for (int k = j; k <= sum; k++) std::swap(mt[i][k], mt[id][k]);
    }
    for (int k = i + 1; k <= sum; k++)
      if (mt[k][j]) {
        int tmp1 = mt[k][j];
        int tmp2 = mt[i][j];
        dv = 1ll * dv * tmp2 % mod;
        for (int p = j; p <= sum; p++) {
          mt[k][p] =
              ((1ll * mt[k][p] * tmp2 - 1ll * mt[i][p] * tmp1) % mod + mod) %
              mod;
        }
      }
  }
  for (int i = 1; i <= sum; i++) ans = 1ll * ans * (mt[i][i] % mod + mod) % mod;
  if (ans == 0) puts("!");
  return 1ll * ans * qpow(dv, mod - 2) % mod;
}
int main() {
  n = rd(), m = rd(), mod = rd();
  for (int i = 1; i <= n; i++) {
    scanf("%s", str[i] + 1);
  }
  for (int i = 1; i <= n + 1; i++) {
    for (int j = 1; j <= m + 1; j++) {
      S++;
      if ((i & 1) == (j & 1)) {
        col[id(i, j)] = 1;
        totb++;
      } else {
        col[id(i, j)] = 0;
        totw++;
      }
    }
  }
  for (int i = 1; i <= S; i++) f[i] = i;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == '\\') {
        add(id(i, j), id(i + 1, j + 1));
      } else if (str[i][j] == '/') {
        add(id(i, j + 1), id(i + 1, j));
      }
    }
  }
  for (int i = 1; i <= S; i++)
    if (f[i] == i) {
      s[col[i]]++;
      w[i] = s[col[i]];
    }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      if (str[i][j] == '*') {
        ADD(col[id(i, j)], w[find(id(i, j))], w[find(id(i + 1, j + 1))]);
        ADD(col[id(i, j + 1)], w[find(id(i, j + 1))], w[find(id(i + 1, j))]);
      }
  }
  int ans = 0;
  if (!tag[0]) ans = (ans + solve(mt[0], s[0])) % mod;
  if (!tag[1]) ans = (ans + solve(mt[1], s[1])) % mod;
  wrt(ans, '\n');
}
