#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int> > g(2e5 + 1);
vector<bool> vis(2e5 + 1);
vector<long long int> s(2e5 + 1), tarjanVal(2e5 + 1);
long long int timer = 0;
void tarjanDfs(long long int u, long long int p) {
  tarjanVal[u] = ++timer;
  vis[u] = true;
  for (auto x : g[u]) {
    if (!vis[x]) tarjanDfs(x, u);
    if (x != p) tarjanVal[u] = min(tarjanVal[u], tarjanVal[x]);
  }
}
void dfs(long long int u) {
  s[u] = 1;
  vis[u] = true;
  for (auto x : g[u]) {
    if (vis[x]) continue;
    dfs(x);
    s[u] += s[x];
  }
}
void solve() {
  long long int n, m, a, b;
  cin >> n >> m >> a >> b;
  for (long long int i = 0; i < m; i++) {
    long long int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  tarjanDfs(a, -1);
  if (tarjanVal[a] == tarjanVal[b]) {
    cout << 0 << '\n';
    ;
  } else {
    for (long long int i = 1; i <= n; i++) {
      vis[i] = false;
    }
    dfs(a);
    long long int sb = s[b];
    for (long long int i = 1; i <= n; i++) {
      vis[i] = false;
      s[i] = 0;
    }
    dfs(b);
    long long int sa = s[a];
    cout << (sa - 1) * (sb - 1) << '\n';
    ;
  }
  for (long long int i = 1; i <= n; i++) {
    tarjanVal[i] = 0;
    g[i].clear();
    vis[i] = false;
    s[i] = 0;
  }
  timer = 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tc;
  tc = 1;
  cin >> tc;
  for (int i = 1; i <= tc; i++) {
    solve();
  }
  return 0;
}
