#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, maxn = 100005;
int n, m, k, fa[maxn], num[maxn];
int find(int x) {
  if (fa[x] == x) return x;
  return fa[x] = find(fa[x]);
}
void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  fa[x] = y;
  num[y] += num[x];
}
int Pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (long long)ans * a % k;
    a = (long long)a * a % k;
    b >>= 1;
  }
  return ans;
}
int main() {
  while (~scanf("%d%d%d", &n, &m, &k)) {
    for (int i = 1; i <= n; i++) fa[i] = i, num[i] = 1;
    while (m--) {
      int u, v;
      scanf("%d%d", &u, &v);
      unite(u, v);
    }
    int ans = 1, cnt = 0;
    for (int i = 1; i <= n; i++)
      if (fa[i] == i) cnt++, ans = (long long)ans * num[i] % k;
    if (cnt == 1)
      ans = 1;
    else
      ans = (long long)ans * Pow(n, cnt - 2) % k;
    printf("%d\n", ans % k);
  }
  return 0;
}
