#include <bits/stdc++.h>
const int MAXN = 100000;
int n, m, K, u, v;
int p[MAXN], sz[MAXN];
void init() {
  for (int i = 0; i < n; ++i) {
    p[i] = i;
    sz[i] = 1;
  }
}
int findp(int k) { return k == p[k] ? k : (p[k] = findp(p[k])); }
inline bool isFriend(int i, int j) { return findp(i) == findp(j); }
inline void setFriend(int i, int j) {
  i = findp(i);
  j = findp(j);
  if (i != j) {
    sz[j] += sz[i];
    p[i] = j;
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &K);
  init();
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &u, &v);
    setFriend(u - 1, v - 1);
  }
  int res = 1;
  for (int i = m = 0; i < n; ++i) {
    if (findp(i) == i) {
      ++m;
      res = (long long)res * sz[i] % K;
    }
  }
  for (int i = 0; i < m - 2; ++i) {
    res = (long long)res * n % K;
  }
  if (m == 1) {
    res = 1 % K;
  }
  printf("%d\n", res);
  return 0;
}
