#include <bits/stdc++.h>
using namespace std;
const long long A = 100000000000000LL, N = 228228;
map<int, int> g;
vector<long long> t;
long long d[N], x, y, i, j, n, m, k;
long long o = 1;
long long get(long long p) {
  if (d[p] != p) d[p] = get(d[p]);
  return d[p];
}
int main() {
  cin >> n >> m >> k;
  for (i = 1; i <= n; i++) d[i] = i;
  while (m--) {
    scanf("%d%d", &x, &y);
    d[get(x)] = get(y);
  }
  for (i = 1; i <= n; i++) d[i] = get(d[i]);
  for (i = 1; i <= n; i++)
    if (!g[d[i]])
      g[d[i]] = 1, t.push_back(d[i]);
    else
      g[d[i]]++;
  for (i = 0; i < t.size(); i++) o *= g[t[i]], o %= k;
  if (t.size() > 1)
    for (i = 0; i < t.size() - 2; i++) o *= n, o %= k;
  if (t.size() == 1)
    cout << (o * ((long double)1 / n)) << "\n";
  else
    cout << o << "\n";
}
