#include <bits/stdc++.h>
using namespace std;
const long long int INF = (long long int)1e9 + 10;
const long long int INFLL = (long long int)1e18 + 10;
const long double EPS = 1e-8;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
template <class T>
inline T sq(T a) {
  return a * a;
}
struct UnionFind {
  vector<int> par, size;
  UnionFind(int n) {
    par = size = vector<int>(n, 1);
    for (long long int i = (0); i < (long long int)(n); i++) par[i] = i;
  }
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    par[x] = y;
    size[y] += size[x];
  }
};
long long int n, m, k;
int main() {
  scanf("%lld %lld %lld", &n, &m, &k);
  UnionFind uf(n);
  for (long long int i = (0); i < (long long int)(m); i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    uf.unite(a, b);
  }
  long long int ans = 1;
  long long int cmp = 0;
  for (long long int i = (0); i < (long long int)(n); i++)
    if (uf.find(i) == i) {
      cmp++;
      ans = (ans * uf.size[i]) % k;
    }
  if (cmp == 1) {
    printf("%lld\n", 1 % k);
    return 0;
  }
  for (long long int i = (0); i < (long long int)(cmp - 2); i++)
    ans = (ans * n) % k;
  printf("%lld\n", ans);
  return 0;
}
