#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   long long ln, lk, lm;   const int MN = 10000;   int mod;   char s[505][505];   pair<int, int> id[2][MN], rid[505][505];   int sz[2];   vector<int> mp[MN], mpc[MN];   long long A[505][505];   int col[MN], C, cnt;   long long ans;   void pp(int N) {     for (int(i) = 1; (i) <= (int)(N); (i)++) {       for (int(j) = 1; (j) <= (int)(N); (j)++) printf( %lld  , A[i][j]);       puts(  );     }     puts(  );   }   long long fastPow(long long x, long long y) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gauss(int N) {     long long tmp = 1;     for (int(i) = 1; (i) <= (int)(N); (i)++)       for (int(j) = 1; (j) <= (int)(N); (j)++)         A[i][j] = (A[i][j] % mod + mod) % mod;     for (int i = 2; i <= N; i++) {       int j = i;       while (j <= N && A[j][i] == 0) j++;       if (j > N) {         return 0;       }       if (i != j) {         for (int(k) = 1; (k) <= (int)(N); (k)++) swap(A[i][k], A[j][k]);         tmp = mod - tmp;       }       for (int j = i + 1; j <= N; j++) {         long long base = A[j][i] * fastPow(A[i][i], mod - 2) % mod;         for (int k = i; k <= N; k++) {           A[j][k] = A[j][k] - A[i][k] * base % mod;           A[j][k] = (A[j][k] % mod + mod) % mod;         }       }       tmp *= A[i][i];       tmp %= mod;     }     return tmp;   }   void dfs(int x, int pa) {     col[x] = C;     for (int c : mp[x])       if (c != pa) {         if (col[c] == 0)           dfs(c, x);         else {           puts( 0 );           exit(0);         }       }   }   bool vis[MN];   void dfs1(int x) {     vis[x] = 1;     cnt++;     for (int c : mpc[x])       if (vis[c] == 0) dfs1(c);   }   void cal(int t) {     for (int(i) = 0; (i) < (int)(MN); (i)++) mp[i].clear();     for (int(i) = 0; (i) < (int)(MN); (i)++) mpc[i].clear();     for (int(i) = 0; (i) < (int)(n); (i)++)       for (int(j) = 0; (j) < (int)(m); (j)++) {         int u, v;         if (s[i][j] ==  /  && rid[i][j + 1].first == t) {           u = rid[i][j + 1].second;           v = rid[i + 1][j].second;           mp[u].push_back(v);           mp[v].push_back(u);         } else if (s[i][j] ==      && rid[i][j].first == t) {           u = rid[i][j].second;           v = rid[i + 1][j + 1].second;           mp[u].push_back(v);           mp[v].push_back(u);         }       }     C = 0;     memset(col, 0, sizeof col);     for (int(i) = 0; (i) < (int)(sz[t]); (i)++)       if (col[i] == 0) {         C++;         dfs(i, -1);       }     for (int(i) = 0; (i) < (int)(505); (i)++)       for (int(j) = 0; (j) < (int)(505); (j)++) A[i][j] = 0;     for (int(i) = 0; (i) < (int)(n); (i)++)       for (int(j) = 0; (j) < (int)(m); (j)++)         if (s[i][j] ==  * ) {           int u, v;           if (rid[i][j + 1].first == t) {             u = rid[i][j + 1].second;             v = rid[i + 1][j].second;           } else {             assert(rid[i][j].first == t);             u = rid[i][j].second;             v = rid[i + 1][j + 1].second;           }           u = col[u];           v = col[v];           if (u == v) continue;           A[u][u]++;           A[v][v]++;           A[u][v]--;           A[v][u]--;           mpc[u].push_back(v);           mpc[v].push_back(u);         }     cnt = 0;     for (int(i) = 0; (i) < (int)(MN); (i)++) vis[i] = 0;     dfs1(1);     if (cnt == C) {       ans += gauss(C);     }     ans += mod;     ans %= mod;   }   void fmain() {     scanf( %d%d%d , &n, &m, &mod);     for (int(i) = 0; (i) < (int)(n); (i)++) scanf( %s , s[i]);     for (int(i) = 0; (i) < (int)(n + 1); (i)++) {       int t = i % 2;       for (int(j) = 0; (j) < (int)(m + 1); (j)++) {         id[t][sz[t]++] = make_pair(i, j);         rid[i][j] = {t, sz[t] - 1};         t ^= 1;       }     }     for (int(i) = 0; (i) < (int)(2); (i)++) cal(i);     printf( %lld n , ans);   }   int main() {     fmain();     return 0;   }