#include <bits/stdc++.h>
using namespace std;
const int sqr = 500;
long long P = 1e9 + 7;
const int arrn = 2e5 + 3;
const int arrn2 = 5e3 + 3;
vector<int> adj[arrn];
void dfs(int u, vector<int> &done, int &cnt, int b, bool &ex) {
  if (!done[u]) {
    if (u == b) ex = 1;
    cnt++;
    done[u] = 1;
    for (auto i : adj[u]) {
      if (!done[i]) dfs(i, done, cnt, b, ex);
    }
  }
}
int check(int a, int b, int n) {
  vector<int> done(n);
  done[a] = 1;
  for (auto i : adj[a]) {
    bool ex = 0;
    int cnt = 1;
    dfs(i, done, cnt, b, ex);
    if (ex == 1) {
      return cnt;
    }
  }
  return 0;
}
void solve() {
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  a--;
  b--;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  long long x = n - check(a, b, n);
  long long y = n - check(b, a, n);
  cout << x * y << '\n';
  for (int i = 0; i < n; i++) adj[i].clear();
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
