#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e5 + 10;
long long n, m, mod;
long long sum[MAXN];
int fa[MAXN], u, v;
int getfa(int x) {
  if (fa[x] == x) return x;
  return fa[x] = getfa(fa[x]);
}
int main() {
  cin >> n >> m >> mod;
  for (int i = 1; i <= n; i++) sum[i] = 1, fa[i] = i;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    u = getfa(u);
    v = getfa(v);
    if (u != v) {
      sum[v] += sum[u];
      fa[u] = v;
    }
  }
  long long c = 0, ret = 1LL;
  for (int i = 1; i <= n; i++)
    if (fa[i] == i) {
      c++;
      ret = ret * sum[i] % mod;
    }
  if (c == 1)
    cout << 1 % mod << endl;
  else {
    for (int i = 0; i < c - 2; i++) ret = ret * n % mod;
    cout << ret << endl;
  }
  return 0;
}
