#include <bits/stdc++.h>
using namespace std;
inline long long read(register long long x = 0, register bool f = false,
                      register char ch = getchar()) {
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = true;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
  return x;
}
static const long long N = 1e5 + 5;
long long mod, n, m, u, v, cnt, Answer = 1;
long long siz[N], fa[N];
inline long long fast_pow(long long a, long long b, long long ans = 1ll) {
  for (; b; b >>= 1, a = (a * a) % mod)
    if (b & 1) ans = (ans * a) % mod;
  return ans % mod;
}
inline long long findf(long long u) {
  return u == fa[u] ? u : fa[u] = findf(fa[u]);
}
signed main() {
  n = read();
  m = read();
  mod = read();
  cnt = 0;
  for (long long i = 1; i <= n; ++i) {
    fa[i] = i;
    siz[i] = 1;
  }
  for (long long i = 1; i <= m; ++i) {
    u = findf(read());
    v = findf(read());
    if (u ^ v) {
      siz[u] += siz[v];
      fa[v] = u;
    }
  }
  for (long long i = 1; i <= n; ++i) {
    if (findf(i) == i) ++cnt, Answer = (Answer * siz[i]) % mod;
  }
  printf("%lld\n", cnt < 2 ? 1 % mod : (fast_pow(n, cnt - 2) * Answer) % mod);
  return 0;
}
