#include <bits/stdc++.h>
using i64 = long long;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int t;
  std::cin >> t;
  while (t--) {
    int n, m, a, b;
    std::cin >> n >> m >> a >> b;
    a--;
    b--;
    std::vector<std::set<int>> e(n);
    for (int i = 0; i < m; i++) {
      int u, v;
      std::cin >> u >> v;
      u--;
      v--;
      e[u].insert(v);
      e[v].insert(u);
    }
    std::vector<bool> vis(n);
    std::vector<int> in(n), low(n);
    int timeStamp = 0;
    std::vector<std::pair<int, int>> bridges;
    std::set<std::pair<int, int>> exist;
    std::function<void(int, int)> dfs = [&](int u, int p) {
      vis[u] = true;
      in[u] = low[u] = timeStamp++;
      for (auto v : e[u]) {
        if (v == p) {
          continue;
        }
        if (vis[v]) {
          low[u] = std::min(low[u], in[v]);
        } else {
          dfs(v, u);
          low[u] = std::min(low[u], low[v]);
          if (low[v] > in[u]) {
            if (!exist.count({u, v}) && !exist.count({v, u})) {
              bridges.emplace_back(v, u);
              exist.insert({u, v});
            }
          }
        }
      }
    };
    dfs(0, -1);
    std::vector<std::vector<int>> edges(n);
    for (auto [u, v] : bridges) {
      e[u].erase(v);
      e[v].erase(u);
    }
    int timer = 0;
    vis.assign(n, false);
    std::vector<int> comp(n), siz(n);
    std::function<int(int)> dfs2 = [&](int u) {
      vis[u] = true;
      int siz = 1;
      comp[u] = timer;
      for (auto v : e[u]) {
        if (!vis[v]) {
          siz += dfs2(v);
        }
      }
      return siz;
    };
    for (int i = 0; i < n; i++) {
      if (!vis[i]) {
        siz[timer] = dfs2(i);
        timer++;
      }
    }
    if (comp[a] == comp[b]) {
      std::cout << 0 << "\n";
      continue;
    }
    for (auto [u, v] : bridges) {
      edges[comp[u]].push_back(comp[v]);
      edges[comp[v]].push_back(comp[u]);
    }
    vis.assign(timer, false);
    std::vector<int> dp(n), p(n);
    std::function<void(int, int)> dfs3 = [&](int u, int par) {
      p[u] = par;
      vis[u] = true;
      dp[u] = siz[u];
      for (auto v : edges[u]) {
        if (!vis[v]) {
          dfs3(v, u);
          dp[u] += dp[v];
        }
      }
    };
    dfs3(comp[a], -1);
    int v = comp[b];
    while (p[v] != comp[a]) v = p[v];
    std::cout << i64(dp[comp[a]] - dp[v] - 1) * (dp[comp[b]] - 1) << "\n";
  }
  return 0;
}
