#include <bits/stdc++.h>
using namespace std;
void swap(long long &a, long long &b) {
  auto tm = a;
  a = b;
  b = tm;
}
const long long mod = 1000000009;
const long long mod2 = 998244353;
const long long INF = (1LL << 50) - 1;
const long long N = 2e5 + 25;
long long n, m, a, b;
vector<long long> v[N];
bool vt[N];
set<long long> s;
void dfs(long long x, vector<long long> c) {
  vt[x] = 1;
  c.push_back(x);
  for (auto &(i) : (v[x])) {
    if (i == b) {
      for (auto &(j) : (c)) s.insert(j);
      return;
    }
    if (vt[i] == 0) dfs(i, c);
  }
}
void bheja_fry() {
  s.clear();
  cin >> n >> m >> a >> b;
  for (long long(i) = (0); (i) < (n + 1); ++(i)) {
    v[i].clear();
    vt[i] = 0;
  }
  long long x, y;
  for (long long(i) = (0); (i) < (m); ++(i)) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  vector<long long> emp;
  dfs(a, emp);
  queue<long long> q;
  for (long long(i) = (0); (i) < (n + 1); ++(i)) vt[i] = 0;
  long long ct = 0;
  vt[b] = 1;
  for (auto &(i) : (v[b])) {
    if (s.find(i) == s.end()) q.push(i);
  }
  while (!q.empty()) {
    x = q.front();
    q.pop();
    if (vt[x]) continue;
    ct++;
    vt[x] = 1;
    for (auto &(i) : (v[x])) {
      if (vt[i] == 0) q.push(i);
    }
  }
  cout << (n - (long long)(s).size() - 1 - ct) * ct;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  for (long long(i) = (1); (i) < (t + 1); ++(i)) {
    bheja_fry();
    if (i < t) cout << "\n";
  }
  return 0;
}
