#include <bits/stdc++.h>
using namespace std;
const int N = 1030;
int n, m, mod, ans = 1, tot, id[N][N], cnt, Id[N * N], s[N][N], fa[N * N];
char str[N][N];
int qpow(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1) res = 1ll * res * x % mod;
    x = 1ll * x * x % mod, y >>= 1;
  }
  return res;
}
void Gauss() {
  for (int i = 1; i < cnt; ++i)
    for (int j = 1; j < cnt; ++j) s[i][j] = (s[i][j] % mod + mod) % mod;
  for (int i = 1; i < cnt; ++i) {
    if (!s[i][i]) {
      for (int j = i + 1; j < cnt; ++j)
        if (s[j][i]) {
          for (int k = i; k < cnt; ++k) swap(s[j][k], s[i][k]);
          break;
        }
      ans = 1ll * (mod - 1) * ans % mod;
    }
    if (!s[i][i]) return (void)(ans = 0);
    int iv = qpow(s[i][i], mod - 2);
    for (int j = i + 1; j < cnt; ++j)
      if (s[j][i]) {
        int tms = 1ll * iv * (mod - s[j][i]) % mod;
        for (int k = i; k < cnt; ++k)
          s[j][k] = (s[j][k] + 1ll * s[i][k] * tms % mod) % mod;
      }
  }
  for (int i = 1; i < cnt; ++i) ans = 1ll * ans * s[i][i] % mod;
}
int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]); }
void merge(int x, int y) {
  if (!x || !y) return;
  if (getfa(x) == getfa(y)) ans = 0;
  fa[getfa(x)] = getfa(y);
}
void lnk(int x, int y) {
  if (!x || !y) return;
  x = Id[getfa(x)], y = Id[getfa(y)];
  if (x == y) return;
  s[x][y]--, s[y][x]--, s[x][x]++, s[y][y]++;
}
int main() {
  scanf("%d%d%d", &n, &m, &mod);
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= m; ++j)
      if ((i & 1) ^ (j & 1)) id[i][j] = ++tot, fa[tot] = tot;
  for (int i = 1; i <= n; ++i) {
    scanf("%s", str[i] + 1);
    for (int j = 1; j <= m; ++j)
      if (str[i][j] == '/')
        merge(id[i][j - 1], id[i - 1][j]);
      else if (str[i][j] == '\\')
        merge(id[i - 1][j - 1], id[i][j]);
  }
  for (int i = 1; i <= tot; ++i)
    if (fa[i] == i) Id[i] = ++cnt;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (str[i][j] == '*')
        lnk(id[i][j - 1], id[i - 1][j]), lnk(id[i - 1][j - 1], id[i][j]);
  Gauss();
  int tmp = ans;
  ans = 1;
  memset(id, 0, sizeof(id)), memset(Id, 0, sizeof(Id)), memset(s, 0, sizeof(s)),
      tot = cnt = 0;
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= m; ++j)
      if ((i & 1) == (j & 1)) id[i][j] = ++tot, fa[tot] = tot;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j)
      if (str[i][j] == '/')
        merge(id[i][j - 1], id[i - 1][j]);
      else if (str[i][j] == '\\')
        merge(id[i - 1][j - 1], id[i][j]);
  }
  for (int i = 1; i <= tot; ++i)
    if (fa[i] == i) Id[i] = ++cnt;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (str[i][j] == '*')
        lnk(id[i][j - 1], id[i - 1][j]), lnk(id[i - 1][j - 1], id[i][j]);
  Gauss();
  cout << (tmp + ans) % mod;
  return 0;
}
