#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int N = 1e5 + 10;
int n, m, MOD, q[N], h[N];
vector<int> v[N];
long long power(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y & 1) ans = ans * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return ans;
}
int BFS(int st) {
  int top = 1, bot = 1;
  q[1] = st;
  h[st] = 1;
  while (top <= bot) {
    int x = q[top++];
    for (auto y : v[x])
      if (!h[y]) {
        h[y] = 1;
        q[++bot] = y;
      }
  }
  return bot;
}
long long solve() {
  long long ans = 1;
  int k = 0;
  for (auto i = 1; i <= n; i++)
    if (!h[i]) {
      ans = ans * BFS(i) % MOD;
      k++;
    }
  if (k > 1) return ans * power(n, k - 2) % MOD;
  return 1 % MOD;
}
int main() {
  scanf("%d%d%d", &n, &m, &MOD);
  for (auto i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  cout << solve();
}
