#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
int i, j, r, x, y, n, m, fn, k;
int f[N];
bool l[N];
vector<int> a[N];
void getfather(int v) {
  l[v] = true;
  r++;
  for (int w = 0; w < a[v].size(); w++)
    if (!l[a[v][w]]) getfather(a[v][w]);
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    x--;
    y--;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  long long sum = 0;
  long long pw = 1 % k;
  for (i = 0; i < n; i++)
    if (!l[i]) {
      r = 0;
      getfather(i);
      f[fn++] = r;
      sum = (sum + r) % k;
      pw = (pw * r) % k;
    }
  if (fn == 1) {
    printf("%d\n", 1 % k);
    return 0;
  }
  for (i = 0; i < fn - 2; i++) pw = (pw * sum) % k;
  printf("%I64d\n", pw);
  return 0;
}
