#include <bits/stdc++.h>
#pragma GCC optimze("Ofast")
using namespace std;
const long long infl = 0x3f3f3f3f3f3f3f3fLL;
const long long infi = 0x3f3f3f3f;
const long long mod = 998244353;
const long long N = 2e5 + 5;
vector<vector<long long> > adj;
long long vis[N];
set<long long> s1, s2;
long long n, m, a, b;
void dfs(long long v, long long rt) {
  vis[v] = 1;
  if (rt == a)
    s1.insert(v);
  else
    s2.insert(v);
  if (v == rt) return;
  for (long long to : adj[v]) {
    if (vis[to]) continue;
    dfs(to, rt);
  }
}
void solve() {
  cin >> n >> m >> a >> b;
  adj.resize(n + 1);
  for (long long i = 1; i <= m; i++) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (long long i = 1; i <= n; i++) vis[i] = 0;
  dfs(a, b);
  for (long long i = 1; i <= n; i++) vis[i] = 0;
  dfs(b, a);
  long long x = 0;
  for (long long t : s1) {
    if (s2.count(t)) x++;
  }
  cout << (s1.size() - x) * (s2.size() - x) << '\n';
  adj.clear();
  s1.clear();
  s2.clear();
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
long long powm(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
long long divide(long long a, long long b) {
  return ((a % mod) * powm(b, mod - 2)) % mod;
}
long long mul(long long a, long long b) {
  return ((a % mod) * (b % mod)) % mod;
}
long long add(long long a, long long b) { return (a % mod + b % mod) % mod; }
