#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
long long n, m, p, tot;
long long cnt[MAXN], siz[MAXN];
int f[MAXN];
int getfather(int x) { return x == f[x] ? x : (f[x] = getfather(f[x])); }
long long power(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % p;
    a = (a * a) % p;
    b >>= 1;
  }
  return ans;
}
int main() {
  scanf("%lld%lld%lld", &n, &m, &p);
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d%d", &x, &y);
    f[getfather(x)] = getfather(y);
  }
  long long ans = 1;
  for (int i = 1; i <= n; i++) {
    cnt[getfather(i)]++;
  }
  for (int i = 1; i <= n; i++) {
    if (cnt[i]) {
      tot++;
      ans = (ans * cnt[i]) % p;
    }
  }
  if (tot == 1) return printf("%d\n", 1 % p), 0;
  ans = power(n, tot - 2) * ans % p;
  printf("%lld\n", ans);
  return 0;
}
