#include <bits/stdc++.h>
using namespace std;
const int LIM = 1e5 + 5, MOD = 1e9 + 7;
long long par[200005];
long long size[200005];
long long rank1[200005];
long long parent(long long i) {
  while (par[i] != i) i = par[i];
  return i;
}
void func(long long a, long long b) {
  a = parent(a);
  b = parent(b);
  if (a == b) return;
  if (rank1[a] < rank1[b]) {
    par[a] = b;
    size[b] += size[a];
    return;
  } else if (rank1[b] < rank1[a]) {
    par[b] = a;
    size[a] += size[b];
    return;
  } else {
    par[b] = a;
    rank1[a]++;
    size[a] += size[b];
  }
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long i, j, k, m, n;
    long long a, b;
    cin >> n >> m >> a >> b;
    vector<pair<long long, long long> > e, wob, woa;
    for (int i = 0; i < m; ++i) {
      cin >> j >> k;
      e.push_back({j, k});
      if ((j != a) && (k != a)) woa.push_back({j, k});
      if ((j != b) && (k != b)) wob.push_back({j, k});
    }
    long long x, y;
    long long cnt = 0;
    for (int i = 0; i < n; ++i) {
      par[i + 1] = i + 1;
      size[i + 1] = 1;
      rank1[i + 1] = 0;
    }
    for (int i = 0; i < wob.size(); ++i) {
      func(wob[i].first, wob[i].second);
    }
    x = n - 1 - size[parent(a)];
    for (int i = 0; i < n; ++i) {
      par[i + 1] = i + 1;
      size[i + 1] = 1;
      rank1[i + 1] = 0;
    }
    for (int i = 0; i < woa.size(); ++i) {
      func(woa[i].first, woa[i].second);
    }
    y = n - 1 - size[parent(b)];
    cout << x * y << "\n";
  }
  return 0;
}
