#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, mod = 1e9 + 7;
const double PI = acos(-1.0);
int n, m, p, k;
int fa[N];
int s[N];
int qpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = 1ll * res * a % p;
    a = 1ll * a * a % p;
    b >>= 1;
  }
  return res;
}
int Find(int x) {
  if (fa[x] == x) return x;
  return fa[x] = Find(fa[x]);
}
void Union(int x, int y) {
  int fx = Find(x), fy = Find(y);
  fa[fx] = fy;
}
int main() {
  scanf("%d%d%d", &n, &m, &p);
  if (p == 1) return puts("0"), 0;
  for (int i = 1; i <= n; ++i) fa[i] = i;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    Union(x, y);
  }
  for (int i = 1; i <= n; ++i) s[Find(i)]++;
  long long ans = 1;
  for (int i = 1; i <= n; ++i)
    if (i == Find(i)) ++k, ans = (ans * 1ll * s[i]) % p;
  if (k == 1) return puts("1"), 0;
  ans = (ans * 1ll * qpow(n, k - 2)) % p;
  printf("%lld\n", ans);
  return 0;
}
