#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, k;
int par[N], sz[N];
int mul(int a, int b) { return (a * 1LL * b) % (k * 1LL); }
int find(int node) {
  if (par[node] == node) return node;
  return par[node] = find(par[node]);
}
void join(int a, int b) {
  a = find(a), b = find(b);
  if (a == b) return;
  if (sz[a] < sz[b]) swap(a, b);
  par[b] = a;
  sz[a] += sz[b];
}
int power(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++) par[i] = i, sz[i] = 1;
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    join(a, b);
  }
  int cmp = 0;
  int res = 1;
  for (int i = 1; i <= n; i++) {
    if (find(i) == i) ++cmp, res = mul(res, sz[i]);
  }
  if (cmp != 1)
    res = mul(res, power(n, cmp - 2));
  else
    res = 1 % k;
  printf("%d\n", res);
}
