#include <bits/stdc++.h>
using namespace std;
int read() {
  int X = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') X = X * 10 + c - '0', c = getchar();
  return X * w;
}
const int N = 100000 + 10;
int mod;
int qpow(int a, int b) {
  int c = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) c = 1ll * c * a % mod;
  return c;
}
int f[N];
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
void merge(int u, int v) {
  u = find(u), v = find(v);
  if (u != v) f[u] = v;
}
int n, m, k, s[N];
int main() {
  n = read(), m = read(), mod = read();
  int ans = 1;
  if (mod == 1) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= n; ++i) f[i] = i;
  for (int i = 1; i <= m; ++i) merge(read(), read());
  for (int i = 1; i <= n; ++i) ++s[find(i)];
  for (int i = 1; i <= n; ++i)
    if (i == find(i)) ++k, ans = 1ll * ans * s[i] % mod;
  if (k == 1) {
    puts("1");
    return 0;
  } else
    ans = 1ll * ans * qpow(n, k - 2) % mod;
  printf("%d\n", ans);
  return 0;
}
