#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > G;
int n, m, a, b;
vector<bool> vis;
vector<vector<int> > comp;
bool dfs(int u, int v, int x, vector<bool> &vi) {
  if (v == u) return true;
  if (u == x || vi[u]) return false;
  bool ret = false;
  vi[u] = true;
  for (int g : G[u]) {
    ret |= dfs(g, v, x, vi);
  }
  return ret;
}
bool pos(int u, int v) {
  vector<bool> vis1(n, false), vis2(n, false);
  return !dfs(u, v, a, vis1) && !dfs(u, v, b, vis2);
}
void dfs1(int u, int c) {
  if (a == u || b == u) {
    return;
  }
  if (vis[u]) {
    return;
  }
  comp[c].push_back(u);
  vis[u] = true;
  for (int v : G[u]) {
    dfs1(v, c);
  }
}
void makeComp() {
  int c = 0;
  for (int i = 0; i < n; i++) {
    if (i == a || i == b) continue;
    if (!vis[i]) {
      comp.push_back({});
      dfs1(i, c);
      c++;
    }
  }
}
void solve() {
  G.clear();
  cin >> n >> m >> a >> b;
  a--;
  b--;
  G.resize(n);
  vis.resize(n);
  comp.clear();
  fill((vis).begin(), (vis).end(), false);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  makeComp();
  long long ans = 0;
  for (auto a : comp) {
    for (auto v : a) {
    }
    for (auto b : comp) {
      if (pos(a[0], b[0])) {
        ans += (long long)a.size() * b.size();
      }
    }
  }
  cout << ans / 2 << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
