#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 1;
vector<long long> v[N];
vector<long long> c(N);
vector<long long> vis(N);
long long n, m, a, b;
bool dfs(long long x, long long p, long long z) {
  if (x == z) {
    c[x] = 2;
    return true;
  }
  c[x] = 1;
  for (auto i : v[x]) {
    if (i == p) continue;
    if (c[i] == 0) continue;
    if (c[i] == 1) continue;
    if (c[i] == 2) {
      c[x] = 2;
      return true;
    }
    if (i == z) {
      c[x] = 2;
      return true;
    }
    if (dfs(i, x, z)) {
      c[x] = 2;
      return true;
    }
  }
  c[x] = 0;
  return false;
}
long long cnt = 0;
void dfs(long long x, long long p) {
  vis[x] = 1;
  cnt++;
  for (auto i : v[x]) {
    if (i == p) continue;
    if (vis[i] == 1) continue;
    dfs(i, x);
  }
}
void solve() {
  cin >> n >> m >> a >> b;
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (long long i = 1; i < n + 1; i++) c[i] = -1;
  c[a] = 0;
  vector<long long> d;
  for (auto i : v[a]) {
    if (!dfs(i, a, b)) d.push_back(i);
  }
  v[a].clear();
  for (auto i : d) v[a].push_back(i);
  for (long long i = 1; i < n + 1; i++) c[i] = -1;
  d.clear();
  c[b] = 0;
  for (auto i : v[b]) {
    if (!dfs(i, b, a)) d.push_back(i);
  }
  v[b].clear();
  for (auto i : d) v[b].push_back(i);
  long long ans = 0;
  for (long long i = 1; i < n + 1; i++) vis[i] = 0;
  cnt = 0;
  dfs(a, a);
  ans = (cnt - 1);
  cnt = 0;
  dfs(b, b);
  ans *= (cnt - 1);
  cout << ans << endl;
  for (long long i = 0; i < n + 1; i++) v[i].clear();
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) solve();
}
