#include <bits/stdc++.h>
int rd() {
  int k = 0;
  char c = getchar();
  while (c > '9' || c < '0') c = getchar();
  while (c >= '0' && c <= '9') k = k * 10 + c - 48, c = getchar();
  return k;
}
const int N = 100001;
int n, m, p, k, f[N], s[N], ans = 1;
int Pow(int x, int a) {
  int s = 1;
  while (a) {
    if (a & 1) s = (long long)s * x % p;
    x = (long long)x * x % p, a >>= 1;
  }
  return s;
}
int F(int x) {
  while (x != f[x]) x = f[x] = f[f[x]];
  return x;
}
int main() {
  n = rd(), m = rd(), p = rd();
  for (int i = 1; i <= n; ++i) f[i] = i;
  for (int i = 1; i <= m; ++i) f[F(rd())] = F(rd());
  for (int i = 1; i <= n; ++i) ++s[F(i)];
  for (int i = 1; i <= n; ++i)
    if (i == f[i]) ans = (long long)ans * s[i] % p, ++k;
  printf("%d\n", (k < 2 ? 1 : (long long)ans * Pow(n, k - 2)) % p);
  return 0;
}
