#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
int powmod(long long a, int b) {
  long long res = 1;
  if (a >= mod) a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a;
    if (res >= mod) res %= mod;
    a = a * a;
    if (a >= mod) a %= mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
vector<int> g[100005];
int v[100005] = {0};
int dfs(int x) {
  int ans = 1, i;
  for (i = 0; i < g[x].size(); i++) {
    if (v[g[x][i]] == 0) {
      v[g[x][i]] = 1;
      ans += dfs(g[x][i]);
    }
  }
  return ans;
}
int main() {
  long long n, m, k;
  cin >> n >> m >> k;
  mod = k;
  int a, b;
  for (k = 0; k < m; k++) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int coun = -2;
  int cur, i;
  long long ans = 1, val = 0;
  for (i = 1; i <= n; i++) {
    if (v[i] == 0) {
      v[i] = 1;
      coun++;
      cur = dfs(i);
      ans = ans * cur % mod;
      val += cur;
    }
  }
  if (val != n) cout << "HI";
  if (coun == -1)
    cout << 1 % mod << '\n';
  else {
    ans = ans * powmod(val, coun) % mod;
    cout << ans << '\n';
  }
  return 0;
}
