#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int MAXN = 100010;
long long n, m, k, u, v, x, y, t, a, b, ans = 1, mod;
bool mark[MAXN];
vector<int> G[MAXN];
long long dfs(int node) {
  mark[node] = 1;
  long long res = 1;
  for (int i : G[node])
    if (!mark[i]) res += dfs(i);
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> mod;
  while (m--) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 1; i <= n; i++)
    if (!mark[i]) {
      t++;
      ans = ans * dfs(i) % mod;
    }
  if (t == 1) return cout << 1 % mod << '\n', 0;
  for (int i = 0; i < t - 2; i++) ans = ans * n % mod;
  cout << ans << '\n';
  return 0;
}
