#include <bits/stdc++.h>
using namespace std;
int curr = 0, k;
inline void dfs(int u, vector<bool> &used, vector<vector<int> > &g) {
  used[u] = true;
  curr++;
  for (const int v : g[u])
    if (!used[v]) dfs(v, used, g);
}
inline int fast_pow(const int a, const int p) {
  if (p == 0) return 1;
  if (p == 1) return a;
  if (p % 2 == 0) {
    int b = fast_pow(a, p / 2);
    return (1ll * b * b) % k;
  }
  return (1ll * a * fast_pow(a, p - 1)) % k;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m >> k;
  vector<vector<int> > g(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<int> comp_size;
  vector<bool> used(n, false);
  for (int i = 0; i < n; ++i)
    if (!used[i]) {
      dfs(i, used, g);
      if (curr > 0) {
        comp_size.push_back(curr);
        curr = 0;
      }
    }
  if (curr > 0) comp_size.push_back(curr);
  long long ans = 1;
  for (int x : comp_size) ans = (1ll * ans * x) % k;
  cout << ((int)comp_size.size() == 1
               ? 1 % k
               : (1ll * ans * fast_pow(n, (int)comp_size.size() - 2)) % k);
  return 0;
}
