#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0', c = getchar();
  }
  return x * f;
}
const int maxn = 1e5 + 10;
int fa[maxn], Siz[maxn], cnt, ans = 1;
int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); }
int pow(int a, int b, int p) {
  int ans = 1;
  for (; b; b >>= 1) {
    if (b & 1) {
      ans = 1ll * ans * a % p;
    }
    a = 1ll * a * a % p;
  }
  return ans;
}
int main() {
  int n = read(), m = read(), p = read();
  for (int i = 1; i <= n; ++i) {
    fa[i] = i, Siz[i] = 1;
  };
  for (int i = 1; i <= m; ++i) {
    int u = get(read()), v = get(read());
    if (u != v) {
      fa[v] = u, Siz[u] += Siz[v];
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (fa[i] == i) {
      ++cnt, ans = 1ll * ans * Siz[i] % p;
    }
  }
  printf("%d\n", cnt < 2 ? 1 % p : 1ll * ans * pow(n, cnt - 2, p) % p);
  return 0;
}
