#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, fa[N], m, k, size[N];
int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]); }
int Pow(int a, int b, int P) {
  int r = 1;
  while (b) {
    if (b & 1) r = 1LL * r * a % P;
    a = 1LL * a * a % P;
    b >>= 1;
  }
  return r;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  int x, y, f1, f2, num = 0;
  for (int i = 1; i <= n; i++) fa[i] = i, size[i] = 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    f1 = getfa(x), f2 = getfa(y);
    if (f1 == f2) continue;
    fa[f1] = f2;
    size[f2] += size[f1];
    num++;
  }
  int ans = 0;
  if (n - num - 2 < 0) {
    ans = 1;
  } else {
    ans = Pow(n, n - num - 2, k);
    for (int i = 1; i <= n; i++)
      if (fa[i] == i) ans = 1LL * ans * size[i] % k;
  }
  printf("%d\n", ans % k);
  return 0;
}
