#include <bits/stdc++.h>
using namespace std;
long long long long binExp(long long long long x, long long long long n) {
  long long long long res = 1;
  while (n) {
    if (n & 1) res = (res * x) % 998244353;
    x = (x * x) % 998244353;
    n >>= 1;
  }
  return res;
}
long long long long modInv(long long long long i) {
  return binExp(i, 998244353 - 2);
}
long long long long add(long long long long a, long long long long b) {
  long long long long res = a + b;
  if (res >= 998244353) res -= 998244353;
  return res;
}
long long long long mul(long long long long a, long long long long b) {
  long long long long res = a * b;
  res %= 998244353;
  return res;
}
long long n, m, a, b;
vector<long long> adj[200001];
long long vis[200001];
bool reached;
void dfs(long long v) {
  if (v == a) return;
  vis[v] = 1;
  if (v == b) {
    reached = 1;
    return;
  }
  for (auto x : adj[v]) {
    if (!vis[x]) {
      dfs(x);
    }
  }
}
void colo(long long v, long long col) {
  vis[v] = col;
  for (auto x : adj[v]) {
    if (vis[x] == 1) {
      colo(x, col);
    }
  }
}
void solve() {
  cin >> n >> m >> a >> b;
  for (long long i = 1; i <= n; i++) {
    adj[i].clear();
    vis[i] = 0;
  }
  long long x, y;
  for (long long i = 0; i < m; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  };
  vis[a] = 3;
  for (auto x : adj[a]) {
    if (!vis[x]) {
      reached = 0;
      dfs(x);
      if (reached) {
        colo(x, 3);
      } else {
        colo(x, 2);
      }
    }
  }
  for (auto x : adj[b]) {
    if (!vis[x]) {
      dfs(x);
      colo(x, 4);
    }
  }
  long long cnt[5] = {0, 0, 0, 0, 0};
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= 4; j++) {
      if (vis[i] == j) cnt[j]++;
    }
  }
  cout << cnt[2] * cnt[4] << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  clock_t start, end;
  start = clock();
  long long t;
  cin >> t;
  while (t--) solve();
  end = clock();
  double time_taken = double(end - start) / double(CLOCKS_PER_SEC);
}
