#include <bits/stdc++.h>
using namespace std;
vector<int> edges[100001];
int nums[100001];
bool visited[100001];
int getNodes(int n) {
  if (visited[n]) return 0;
  visited[n] = true;
  int ret = 1;
  for (int i = 0; i < edges[n].size(); i++) {
    ret += getNodes(edges[n][i]);
  }
  return ret;
}
int main() {
  int n, m, a, b;
  long long k;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) edges[i].clear(), visited[i] = false;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--, b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  int cont = 0;
  for (int i = 0; i < n; i++) {
    if (!visited[i]) nums[cont++] = getNodes(i);
  }
  long long ans = 1;
  if (cont > 1) {
    ans = nums[0] * nums[1];
    for (int i = 2; i < cont; i++) {
      ans *= nums[i], ans %= k;
      ans *= n, ans %= k;
    }
  }
  cout << ans % k << endl;
  return 0;
}
