#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::function<int(int)> dfs = [&](int u) {
      vis[u] = true;
      for (auto v : e[u]) {
        if (!vis[v]) {
          if (v == b) {
            e[u].erase(v);
            e[v].erase(u);
            return 1;
          }
          int val = dfs(v);
          if (val == 1) {
            e[u].erase(v);
            e[v].erase(u);
            if (u == a) {
              return 2;
            }
            return 1;
          } else if (val == 2) {
            return 2;
          }
        }
      }
      return 0;
    };
    dfs(a);
    std::function<int(int)> dfs2 = [&](int u) {
      vis[u] = true;
      int siz = 0;
      for (auto v : e[u]) {
        if (!vis[v]) {
          if (v == b) {
            return -1;
          }
          int val = dfs2(v);
          if (val == -1) {
            return -1;
          }
          siz += val + 1;
        }
      }
      return siz;
    };
    vis.assign(n, false);
    int sa = dfs2(a), sb = dfs2(b);
    if (sa == -1) {
      std::cout << 0 << "\n";
    } else {
      std::cout << i64(sa) * sb << "\n";
    }
  }
  return 0;
}
