#include <bits/stdc++.h>
using namespace std;
template <typename T>
void r1(T &x) {
  x = 0;
  char c(getchar());
  int f(1);
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  x *= f;
}
const int maxn = 2e5 + 5;
const int maxm = maxn << 1;
typedef int room[maxn];
int n, m, mod;
int fa[maxn];
int sz[maxn];
int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); }
int ksm(int x, int mi) {
  int res(1);
  while (mi) {
    if (mi & 1) res = 1ll * res * x % mod;
    mi >>= 1;
    x = 1ll * x * x % mod;
  }
  return res;
}
signed main() {
  int i, j;
  r1(n), r1(m), r1(mod);
  for (i = 1; i <= n; ++i) fa[i] = i, sz[i] = 1;
  for (i = 1; i <= m; ++i) {
    int u, v;
    r1(u), r1(v);
    int s1 = get(u), s2 = get(v);
    if (s1 != s2) {
      fa[s1] = s2;
      sz[s2] += sz[s1];
      sz[s2] %= mod;
    }
  }
  int ans(1), ct(0);
  for (i = 1; i <= n; ++i) {
    if (fa[i] == i) {
      ++ct;
      ans = 1ll * ans * sz[i] % mod;
    }
  }
  printf("%lld\n", ct < 2 ? 1 % mod : 1ll * ksm(n, ct - 2) * ans % mod);
  return 0;
}
