#include <bits/stdc++.h>
using namespace std;
void read(int &k) {
  k = 0;
  char x = getchar();
  while (x < '0' || x > '9') x = getchar();
  while (x >= '0' && x <= '9') {
    k = k * 10 - 48 + x;
    x = getchar();
  }
}
int n, m, k, M;
bool use[100010];
struct graph {
  int a[100010], b[200010], c[200010], p;
  void addedge(int x, int y) {
    c[++p] = a[x];
    a[x] = p;
    b[p] = y;
    c[++p] = a[y];
    a[y] = p;
    b[p] = x;
  }
  int dfs(int k) {
    use[k] = true;
    int ret = 0;
    for (int i = a[k]; i; i = c[i])
      if (!use[b[i]]) ret += dfs(b[i]);
    return ret + 1;
  }
} a;
int x, y;
long long ans;
long long powe(long long A, long long B) {
  long long ret = 1 % k;
  for (int i = 0; i < B; i++) ret = ret * A % k;
  return ret;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    a.addedge(x, y);
  }
  ans = 1 % k;
  for (int i = 1; i <= n; i++)
    if (!use[i]) ans = (ans * a.dfs(i)) % k, M++;
  if (M == 1)
    ans = 1 % k;
  else
    ans = ans * powe(n, M - 2) % k;
  cout << ans << endl;
  return 0;
}
