#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > adj;
vector<int> vis;
vector<int> mkg;
void dfs(int u, int p, int jp, int k) {
  vis[u] = 1;
  mkg[u] += k;
  for (auto v : adj[u]) {
    if (v == p || v == jp) continue;
    if (vis[v] == 1) continue;
    dfs(v, u, jp, k);
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    a--, b--;
    adj.clear();
    adj.resize(n);
    while (m--) {
      int u, v;
      cin >> u >> v;
      u--, v--;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    mkg.clear();
    mkg.resize(n);
    vis.clear();
    vis.resize(n);
    dfs(a, a, b, 1);
    vis.clear();
    vis.resize(n);
    dfs(b, b, a, 2);
    long long cnt1 = -1, cnt2 = -1;
    for (auto i : mkg) {
      if (i == 1)
        cnt1++;
      else if (i == 2)
        cnt2++;
    }
    cout << cnt1 * cnt2 << endl;
  }
  return 0;
}
