#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, k, mod, ans = 1, f[100010], siz[100010];
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ '0');
    c = getchar();
  }
  return x * f;
}
inline int get(int x) { return f[x] == x ? x : f[x] = get(f[x]); }
inline int Pow(int x, int k) {
  int res = 1;
  while (k) {
    if (k & 1) res = 1ll * res * x % mod;
    x = 1ll * x * x % mod;
    k >>= 1;
  }
  return res;
}
int main() {
  n = read();
  m = read();
  mod = read();
  for (int i = 1; i <= n; i++) {
    f[i] = i;
    siz[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    x = get(read());
    y = get(read());
    if (x == y) continue;
    f[x] = y;
    siz[y] += siz[x];
  }
  for (int i = 1; i <= n; i++)
    if (i == get(i)) {
      ans = 1ll * ans * siz[get(i)] % mod;
      k++;
    }
  printf("%lld", k < 2 ? 1ll % mod : 1ll * ans * Pow(n, k - 2) % mod);
  return 0;
}
