#include <bits/stdc++.h>
using namespace std;
char gchar() {
  static char tbuf1[1000], *tmp_st = tbuf1, *tmp_ed = tbuf1;
  if (tmp_st == tmp_ed) {
    int len = fread(tbuf1, 1, 1000, stdin);
    if (len == 0) return -1;
    tmp_ed = tbuf1 + len;
    tmp_st = tbuf1;
  }
  return *(tmp_st++);
}
inline bool gn(int &x) {
  char c, sg = 0;
  while (c = gchar(), (c > '9' || c < '0') && c != '-' && c != -1)
    ;
  if (c == -1) return 0;
  for ((c == '-' ? sg = 1, c = gchar() : 0), x = 0; c >= '0' && c <= '9';
       c = gchar())
    x = (x << 1) + (x << 3) + c - '0';
  if (sg) x = -x;
  return 1;
}
inline int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = (long long)a * a % m)
    if (b & 1) ans = (long long)ans * a % m;
  return ans;
}
const int NN = 100010;
int root[NN], siz[NN];
inline int Root(int u) {
  return (u == root[u]) ? u : (root[u] = Root(root[u]));
}
int main() {
  int n, m, k, u, v;
  gn(n);
  gn(m);
  gn(k);
  for (int i = 1; i <= n; i++) root[i] = i, siz[i] = 1;
  long long ans = 1ll;
  int lump = n;
  while (m--) {
    gn(u);
    gn(v);
    u = Root(u);
    v = Root(v);
    if (u != v) {
      lump--;
      if (siz[u] < siz[v]) {
        siz[v] += siz[u];
        root[u] = v;
      } else {
        siz[u] += siz[v];
        root[v] = u;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (root[i] == i) {
      ans = ans * siz[i] % k;
    }
  }
  if (lump == 1)
    ans = 1 % k;
  else
    ans = ans * power(n, lump - 2, k) % k;
  cout << ans << endl;
  return 0;
}
