#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
vector<long long int> adj[3000005], adj1[3000005];
long long int f[3000005], siz[3000005], st[3000005], en[3000005], t,
    sub[3000005], pa[3000005];
long long int fin(long long int u) {
  if (f[u] == u) return f[u];
  return f[u] = fin(f[u]);
}
long long int unio(long long int x, long long int y) {
  if (siz[y] > siz[x]) swap(x, y);
  siz[x] += siz[y];
  f[y] = x;
}
void dfs(long long int u, long long int par) {
  st[u] = t++;
  sub[u] = 1;
  long long int i;
  for (i = 0; i < adj1[u].size(); i++) {
    long long int p = adj1[u][i];
    if (p == par) continue;
    dfs(p, u);
    pa[p] = u;
    sub[u] += sub[p];
  }
  en[u] = t;
}
int main() {
  long long int tc, n, m, x, y, i, j, a, b;
  cin >> tc;
  while (tc--) {
    cin >> n >> m >> a >> b;
    for (i = 1; i <= n; i++) {
      f[i] = i;
      siz[i] = 1;
      adj[i].clear();
      adj1[i].clear();
      pa[i] = 0;
    }
    for (i = 1; i <= m; i++) {
      cin >> x >> y;
      adj[x].push_back(y);
      adj[y].push_back(x);
      long long int x1 = fin(x);
      long long int y1 = fin(y);
      if (x1 == y1) continue;
      unio(x1, y1);
      adj1[x].push_back(y);
      adj1[y].push_back(x);
    }
    t = 0;
    dfs(a, -1);
    long long int suba = 1, subb = 0;
    long long int kk;
    for (i = 0; i < adj1[a].size(); i++) {
      long long int p = adj1[a][i];
      if (st[p] <= st[b] && en[p] >= st[b]) {
        kk = p;
        continue;
      }
      suba += sub[p];
    }
    subb = sub[b];
    long long int ans = (suba - 1) * (subb - 1);
    cout << ans << endl;
  }
  return 0;
}
