#include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
int n, m, k, fa[maxn], c[maxn];
int fd(int x) {
  if (fa[x] == x) return x;
  return fa[x] = fd(fa[x]);
}
int power(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = (long long)z * x % k;
    x = (long long)x * x % k;
  }
  return z;
}
int main() {
  int i, a, b;
  scanf("%d%d%d", &n, &m, &k);
  for (i = 1; i <= n; ++i) fa[i] = i;
  for (i = 1; i <= m; ++i) {
    scanf("%d%d", &a, &b);
    a = fd(a);
    b = fd(b);
    if (a != b) fa[a] = b;
  }
  for (i = 1; i <= n; ++i) {
    a = fd(i);
    ++c[a];
  }
  m = 0;
  for (i = 1; i <= n; ++i)
    if (c[i]) ++m;
  if (m == 1) {
    printf("%d\n", 1 % k);
    return 0;
  }
  a = 1, b = 0;
  for (i = 1; i <= n; ++i)
    if (c[i]) a = (long long)a * c[i] % k;
  printf("%d\n", (long long)a * power(n, m - 2) % k);
  return 0;
}
