#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 5;
long long n, m, t;
long long a, b;
long long total = 0;
long long head[MAXN], nxt[MAXN], to[MAXN], len[MAXN];
void add(long long a, long long b, long long c = 1) {
  nxt[++total] = head[a];
  to[total] = b;
  len[total] = c;
  head[a] = total;
}
set<long long> aa, bb;
void dfs(long long x, long long y, set<long long> &se) {
  se.insert(x);
  for (long long i = head[x]; i; i = nxt[i]) {
    long long tmpto = to[i];
    if (tmpto != y && !se.count(tmpto)) {
      dfs(tmpto, y, se);
    }
  }
}
int main() {
  cin >> t;
  while (t--) {
    aa.clear();
    bb.clear();
    cin >> n >> m >> a >> b;
    for (long long i = 1; i <= total; i++) head[i] = 0;
    total = 0;
    for (long long i = 1; i <= m; i++) {
      long long x, y;
      scanf("%lld", &x);
      scanf("%lld", &y);
      add(x, y);
      add(y, x);
    }
    dfs(a, b, aa);
    dfs(b, a, bb);
    long long both = 0;
    for (long long x : aa) {
      if (bb.count(x)) both++;
    }
    cout << (aa.size() - both - 1) * (bb.size() - both - 1) << endl;
  }
}
