#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n, m, P, ans, t, cnt;
int ID[N * N], id[N][N], f[N * N], D[N * N], d[N][N], A[N][N];
bool bo[N * N];
char s[N][N];
int find(int x) {
  if (x == f[x]) return x;
  return f[x] = find(f[x]);
}
long long Pow(long long a, int x) {
  long long res = 1;
  while (x) {
    if (x & 1) res = res * a % P;
    a = a * a % P;
    x >>= 1;
  }
  return res;
}
int cal() {
  cnt--;
  int t = 0, res = 1;
  for (int i = 1; i <= cnt; i++) {
    if (A[i][i] == 0) {
      for (int j = i + 1; j <= cnt; j++) {
        if (A[j][i] == 0) continue;
        t ^= 1;
        for (int k = 1; k <= cnt; k++) swap(A[i][k], A[j][k]);
        break;
      }
    }
    if (A[i][i] == 0) break;
    for (int j = i + 1; j <= cnt; j++) {
      if (A[j][i] == 0) continue;
      long long tmp = Pow(A[i][i], P - 2) * A[j][i] % P;
      for (int k = i; k <= cnt; k++) {
        A[j][k] -= A[i][k] * tmp % P;
        (A[j][k] += P) %= P;
      }
    }
  }
  for (int i = 1; i <= cnt; i++) res = (long long)res * A[i][i] % P;
  if (t) return P - res;
  return res;
}
int work(int o) {
  for (int i = 0; i < N * N; i++) bo[i] = D[i] = ID[i] = 0;
  t = cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if ((i + j) % 2 == o)
        id[i][j] = ++t;
      else
        id[i][j] = 0;
    }
  }
  for (int i = 1; i <= t; i++) f[i] = i;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < m; j++) {
      if (s[i][j] == '/' && (i + j + 1) % 2 == o) {
        if (find(id[i + 1][j]) == find(id[i][j + 1])) return 0;
        f[find(id[i + 1][j])] = find(id[i][j + 1]);
      }
      if (s[i][j] == '\\' && (i + j) % 2 == o) {
        if (find(id[i][j]) == find(id[i + 1][j + 1])) return 0;
        f[find(id[i][j])] = find(id[i + 1][j + 1]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if ((i + j) % 2 == o) {
        if (!bo[find(id[i][j])]) {
          bo[find(id[i][j])] = 1;
          ID[find(id[i][j])] = ++cnt;
          id[i][j] = cnt;
        } else {
          id[i][j] = ID[find(id[i][j])];
        }
      }
    }
  }
  for (int i = 1; i <= cnt; i++)
    for (int j = 1; j <= cnt; j++) d[i][j] = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < m; j++) {
      if (s[i][j] != '*') continue;
      if ((i + j + 1) % 2 == o && id[i + 1][j] != id[i][j + 1]) {
        D[id[i + 1][j]]++;
        D[id[i][j + 1]]++;
        d[id[i + 1][j]][id[i][j + 1]]++;
        d[id[i][j + 1]][id[i + 1][j]]++;
      }
      if ((i + j) % 2 == o && id[i][j] != id[i + 1][j + 1]) {
        D[id[i][j]]++;
        D[id[i + 1][j + 1]]++;
        d[id[i][j]][id[i + 1][j + 1]]++;
        d[id[i + 1][j + 1]][id[i][j]]++;
      }
    }
  }
  for (int i = 1; i <= cnt; i++) {
    for (int j = 1; j <= cnt; j++) {
      if (i == j)
        A[i][i] = D[i] % P;
      else
        A[i][j] = (P - d[i][j] % P) % P;
    }
  }
  return cal();
}
int main() {
  scanf("%d %d %d", &n, &m, &P);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  n++;
  m++;
  (ans += work(1)) %= P;
  (ans += work(0)) %= P;
  cout << ans << endl;
}
