#include <bits/stdc++.h>
using namespace std;
long long N, M, K, MOD;
int Gr[100000], Size[100000];
int get_par(int x) {
  int head = x, tmp;
  while (head != Gr[head]) head = Gr[head];
  while (x != head) {
    tmp = Gr[x];
    Gr[x] = head;
    x = tmp;
  }
  return head;
}
bool merge(int a, int b) {
  if (get_par(a) == get_par(b)) return false;
  Size[Gr[b]] += Size[Gr[a]];
  Gr[Gr[a]] = Gr[b];
  return true;
}
int main() {
  int i, a, b;
  cin >> N >> M >> MOD;
  for (i = 0; i < (int)(N); i++) Gr[i] = i, Size[i] = 1;
  long long K = N;
  for (i = 0; i < (int)(M); i++) {
    cin >> a >> b;
    a--, b--;
    if (merge(a, b)) K--;
  }
  if (K == 1) {
    cout << 1 % MOD << endl;
  } else {
    long long res = 1;
    for (i = 0; i < (int)(N); i++)
      if (Gr[i] == i) res = (res * Size[i]) % MOD;
    for (i = 0; i < (int)(K - 2); i++) {
      res = (res * N) % MOD;
    }
    cout << res << endl;
  }
  return 0;
}
