#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, K, x, y;
int f[100010], s[100010];
long long an = 1;
int get(int x) { return f[x] == x ? x : f[x] = get(f[x]); }
int main() {
  scanf("%d%d%d", &n, &m, &K);
  for (i = 1; i <= n; i++) f[i] = i;
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    f[get(x)] = get(y);
  }
  for (i = 1; i <= n; i++) s[get(i)]++;
  k = 0;
  for (i = 1; i <= n; i++)
    if (get(i) == i) an = an * s[i] % K, k++;
  for (i = 1; i <= k - 2; i++) an = an * n % K;
  if (k == 1) an = 1;
  printf("%I64d\n", an % K);
  return 0;
}
