#include <bits/stdc++.h>
using namespace std;
vector<bool> bfs(long long n, vector<long long> adj[], long long s,
                 long long oth) {
  vector<long long> vis(n + 1);
  queue<long long> q;
  q.push(s);
  vis[s] = 1;
  bool viss = 1;
  vector<bool> ans(n + 1);
  while (q.empty() ^ 1) {
    long long p = q.front();
    q.pop();
    ans[p] = viss;
    for (long long& x : adj[p]) {
      if (x == oth) continue;
      if (vis[x]) continue;
      vis[x] = 1;
      q.push(x);
    }
  }
  return ans;
}
void solve() {
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  vector<long long> adj[n + 1];
  while (m--) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  vector<bool> w, ww;
  w = bfs(n, adj, a, b);
  ww = bfs(n, adj, b, a);
  long long in = 0 - 1, out = 0 - 1;
  for (long long i = 1; i <= n; i++) {
    if (w[i] && ww[i] == 0) {
      out++;
    } else if (w[i] == 0 && ww[i])
      in++;
  }
  cout << in * out;
}
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    solve();
    cout << endl;
  }
  return 0;
}
