#include <bits/stdc++.h>
using namespace std;
int father[100010], size[100010];
int find(int x) { return father[x] == 0 ? x : father[x] = find(father[x]); }
void unionSet(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx == fy) {
    return;
  }
  if (size[fx] > size[fy]) {
    father[fy] = fx, size[fx] += size[fy];
  } else {
    father[fx] = fy, size[fy] += size[fx];
  }
}
int main() {
  int n, m, k;
  while (cin >> n >> m >> k) {
    for (int i = 1; i <= n; ++i) {
      father[i] = 0, size[i] = 1;
    }
    int x, y;
    for (int i = 0; i < m; ++i) {
      cin >> x >> y;
      unionSet(x, y);
    }
    long long ans = 1;
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
      if (father[i] == 0) {
        ans = (ans * size[i]) % k;
        ++cnt;
      }
    }
    if (cnt == 1) {
      cout << 1 % k << endl;
      continue;
    }
    for (int i = 1; i <= cnt - 2; ++i) {
      ans = (ans * n) % k;
    }
    cout << ans << endl;
  }
  return 0;
}
