#include <bits/stdc++.h>
using namespace std;
vector<long long> g[200001];
long long v[200001];
long long cnt;
void dfs(long long a, long long b) {
  if (v[a] == 1 || a == b) return;
  cnt++;
  v[a] = 1;
  for (auto i : g[a]) dfs(i, b);
}
void solve() {
  long long i, j, k, l, n, m, a, b, ans = 0;
  string s;
  cin >> n >> m >> a >> b;
  for (i = 0; i < m; i++) {
    cin >> j >> k;
    g[j].push_back(k);
    g[k].push_back(j);
  }
  for (k = 0; k <= n; k++) v[k] = 0;
  cnt = 1;
  dfs(a, b);
  i = n - cnt;
  for (k = 0; k <= n; k++) v[k] = 0;
  cnt = 1;
  dfs(b, a);
  j = n - cnt;
  cout << (i * j) << "\n";
  for (i = 0; i <= n; i++) g[i].clear();
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
