#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5, maxm = 1e5 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-8, pi = acos(-1.0);
int f[maxn];
long long quickPow(long long a, long long b, long long p) {
  long long r = 1;
  while (b) {
    if (b & 1) r = r * a % p;
    b >>= 1;
    a = a * a % p;
  }
  return r;
}
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
void merge(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx != fy) f[fx] = fy;
}
int n, m, k, x, y;
map<int, int> mp;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++) f[i] = i;
  while (m--) {
    scanf("%d%d", &x, &y);
    merge(x, y);
  }
  for (int i = 1; i <= n; i++) mp[find(i)]++;
  long long ans = 1;
  for (auto it = mp.begin(); it != mp.end(); it++) ans = ans * it->second % k;
  if (mp.size() > 1)
    ans = ans * quickPow(n, mp.size() - 2, k) % k;
  else
    ans = 1 % k;
  printf("%I64d\n", ans);
  return 0;
}
