#include <bits/stdc++.h>
const int MAXN = 1e5 + 19;
int qpow(int a, int b, int p) {
  int res = 1;
  while (b) {
    if (b & 1) res = (long long)res * a % p;
    a = (long long)a * a % p, b >>= 1;
  }
  return res;
}
int n, m, k, p;
int fa[MAXN], size[MAXN];
int getf(int node) {
  return fa[node] == node ? node : fa[node] = getf(fa[node]);
}
int main() {
  std::scanf("%d%d%d", &n, &m, &p);
  for (int i = 1; i <= n; ++i) fa[i] = i, size[i] = 1;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    std::scanf("%d%d", &u, &v);
    if (getf(u) != getf(v)) {
      size[getf(v)] += size[getf(u)];
      fa[getf(u)] = getf(v);
    }
  }
  int ans = 1;
  for (int i = 1; i <= n; ++i)
    if (fa[i] == i) ++k, ans = (long long)ans * size[i] % p;
  if (k >= 2)
    ans = (long long)ans * qpow(n, k - 2, p) % p;
  else
    ans = 1;
  std::printf("%d\n", ans % p);
  return 0;
}
