#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200005];
int v[200005], c[200005];
void dfs(int f, int a) {
  c[f] += a;
  v[f] = 1;
  for (auto it : adj[f]) {
    if (!v[it]) dfs(it, a);
  }
}
int main() {
  ios::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    for (int i = 1; i <= n; i++) adj[i].clear();
    for (int i = 0; i < m; i++) {
      int u, v;
      cin >> u >> v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) c[i] = 0;
    for (int i = 1; i <= n; i++) v[i] = 0;
    v[a] = v[b] = 1;
    dfs(a, 1);
    for (int i = 1; i <= n; i++) v[i] = 0;
    v[a] = v[b] = 1;
    dfs(b, 2);
    int c1 = -1, c2 = -1;
    for (int i = 1; i <= n; i++) {
      c1 += (c[i] == 1);
      c2 += (c[i] == 2);
    }
    long long ans = c1;
    ans *= c2;
    cout << ans << "\n";
  }
  return 0;
}
