#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
template <class T>
void dbs(string str, T t) {
  cout << str << " : " << t << endl;
}
template <class T, class... second>
void dbs(string str, T t, second... s) {
  int idx = str.find(',');
  cout << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
template <class second, class T>
ostream& operator<<(ostream& os, const pair<second, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class second, class T>
ostream& operator<<(ostream& os, const map<second, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void prc(T a, T b) {
  cout << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cout << ", ";
    cout << *i;
  }
  cout << "]";
  cout << endl;
}
struct DSU {
  vector<int> p, r;
  DSU(int n) : p(n), r(n, 1) {
    for (int i = (0); i <= (n - 1); ++i) p[i] = i;
  }
  int get(int i) {
    if (p[i] != i) p[i] = get(p[i]);
    return p[i];
  }
  int connect(int i, int j) {
    int x = get(i), y = get(j);
    if (x == y) return 0;
    if (r[x] > r[y]) swap(x, y);
    p[x] = y;
    r[y] += r[x];
    return 1;
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  DSU dsu(n);
  for (int i = (1); i <= (m); ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    dsu.connect(a, b);
  }
  int ans = 1;
  int no = 0;
  for (int i = (0); i <= (n - 1); ++i)
    if (i == dsu.get(i)) ans = (ans * 1LL * dsu.r[i]) % k, no++;
  for (int i = (1); i <= (no - 2); ++i) ans = (ans * 1LL * n) % k;
  if (no == 1) ans = 1 % k;
  cout << ans;
  return 0;
}
