#include <bits/stdc++.h>
using namespace std;
const int MAX = 100100;
vector<int> adj[MAX];
bool mark[MAX];
int n;
int DFS(int v) {
  mark[v] = 1;
  int sz = 1;
  for (__typeof((adj[v]).begin()) it = (adj[v]).begin(); it != (adj[v]).end();
       it++)
    if (!mark[*it]) sz += DFS(*it);
  return sz;
}
int main() {
  ios_base::sync_with_stdio(false);
  int m, k;
  cin >> n >> m >> k;
  for (int cnt = 0; cnt < (m); cnt++) {
    int x, y;
    cin >> x >> y;
    adj[--y].push_back(--x);
    adj[x].push_back(y);
  }
  vector<int> components;
  for (int i = 0; i < (n); i++)
    if (!mark[i]) components.push_back(DFS(i));
  if ((int)(components).size() == 1) {
    cout << 1 % k << endl;
    return 0;
  }
  long long ans = 1;
  for (int cnt = 0; cnt < ((int)(components).size() - 2); cnt++)
    ans = (ans * n) % k;
  for (__typeof((components).begin()) i = (components).begin();
       i != (components).end(); i++)
    ans = (ans * (*i)) % k;
  cout << ans << endl;
  return 0;
}
