#include <bits/stdc++.h>
using namespace std;
const int maxN = 100005;
int n, m, k;
vector<int> g[maxN];
bool was[maxN];
int dfs(int v) {
  was[v] = true;
  int res = 1;
  for (int to : g[v]) {
    if (!was[to]) res += dfs(to);
  }
  return res;
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int res = 1 % k;
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (!was[i]) {
      res = (1LL * res * dfs(i)) % k;
      ++cnt;
    }
  }
  for (int i = 0; i < cnt - 2; ++i) {
    res = (1LL * res * n) % k;
  }
  if (cnt == 1) res = 1 % k;
  printf("%d\n", res);
  return 0;
}
