#include <bits/stdc++.h>
using namespace std;
int sz[111111];
int h[111111];
int p[111111];
int n, m, k;
int P(int first) {
  return (p[first] == first) ? (first) : (p[first] = P(p[first]));
}
inline void U(int first, int second) {
  if (h[first] >= h[second]) {
    p[second] = first;
    if (h[first] == h[second]) ++h[first];
    sz[first] += sz[second];
  } else {
    p[first] = second;
    sz[second] += sz[first];
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < n; ++i) {
    sz[i] = 1;
    p[i] = i;
  }
  for (int i = 0; i < m; ++i) {
    int st, fn;
    scanf("%d%d", &st, &fn);
    --st;
    --fn;
    if (P(st) != P(fn)) U(P(st), P(fn));
  }
  int ans = 1;
  int comp = 0;
  for (int i = 0; i < n; ++i) {
    if (P(i) == i) {
      ans = ((long long)ans * sz[i]) % k;
      ++comp;
    }
  }
  if (comp == 1) {
    cout << 1 % k << endl;
    return 0;
  }
  for (int i = 0; i < comp - 2; ++i) {
    ans = ((long long)ans * n) % k;
  }
  cout << ans << endl;
  return 0;
}
