#include <bits/stdc++.h>
using namespace std;
int cha[100100], cnt[100100];
long long ans;
int n, m, k, comp;
int find(int x) {
  if (cha[x] == x) return x;
  cha[x] = find(cha[x]);
  return cha[x];
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < n; i++) cha[i] = i;
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    int f1 = find(u);
    int f2 = find(v);
    if (f1 != f2) cha[f1] = f2;
  }
  for (int i = 0; i < n; i++) {
    cnt[find(i)]++;
    if (find(i) == i) comp++;
  }
  ans = 1 % k;
  if (comp > 1) {
    for (int i = 0; i < n; i++)
      if (cnt[i] > 0) ans = (ans * cnt[i]) % k;
    for (int i = 1; i <= comp - 2; i++) ans = (ans * n) % k;
  }
  cout << ans << endl;
}
