#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int MN = 100111;
int n, m, BASE;
vector<int> ke[MN];
long long power(int x, int k) {
  if (k == 0) return 1 % BASE;
  if (k == 1) return x % BASE;
  long long mid = power(x, k >> 1);
  mid = (mid * mid) % BASE;
  if (k & 1)
    return (mid * x) % BASE;
  else
    return mid;
}
bool mark[MN];
int first, last, qu[MN];
void bfs(int u) {
  first = 1, last = 1;
  qu[1] = u;
  mark[u] = true;
  while (first <= last) {
    int u = qu[first++];
    for (int i = 0, _a = (ke[u].size()); i < _a; i++) {
      int v = ke[u][i];
      if (mark[v]) continue;
      mark[v] = true;
      qu[++last] = v;
    }
  }
}
int main() {
  while (scanf("%d%d%d", &n, &m, &BASE) == 3) {
    for (int i = (1), _b = (n); i <= _b; i++) ke[i].clear();
    memset(mark, false, sizeof mark);
    while (m--) {
      int u, v;
      scanf("%d%d", &u, &v);
      ke[u].push_back(v);
      ke[v].push_back(u);
    }
    long long res = 1, cnt = 0;
    for (int i = (1), _b = (n); i <= _b; i++)
      if (!mark[i]) {
        bfs(i);
        res = (res * last) % BASE;
        ++cnt;
      }
    if (cnt == 1) {
      printf("%d\n", 1 % BASE);
      continue;
    }
    res = (res * power(n, cnt - 2)) % BASE;
    printf("%d\n", (int)res);
  }
  return 0;
}
