#include <bits/stdc++.h>
using namespace std;
const int N = 200 * 1001, M = 500 * 1001;
long long n, m, U, V, comp[2][N], cnt, cnt2, num0[N], num1[N];
bool bad[N], mark[2][N];
vector<long long> adj[N];
map<pair<long long, long long>, long long> mp;
set<pair<long long, long long>> s;
void dfs(int u, bool type) {
  mark[type][u] = true;
  comp[type][u] = cnt;
  for (auto v : adj[u]) {
    if (!mark[type][v] && !bad[v]) dfs(v, type);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m >> U >> V;
    U--, V--;
    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);
    }
    bad[U] = true;
    for (int i = 0; i < n; i++) {
      if (U != i && !mark[0][i]) {
        dfs(i, 0);
        cnt++;
      }
    }
    bad[U] = false;
    bad[V] = true;
    int ccnt = cnt;
    cnt = 0;
    for (int i = 0; i < n; i++) {
      if (V != i && !mark[1][i]) {
        dfs(i, 1);
        cnt++;
      }
    }
    bad[V] = false;
    for (int i = 0; i < n; i++) {
      if (i != V && i != U) {
        num0[comp[0][i]]++;
        num1[comp[1][i]]++;
      }
    }
    long long res = 0;
    for (int i = 0; i < ccnt; i++) res += 1LL * num0[i] * (num0[i] - 1) / 2;
    for (int i = 0; i < cnt; i++) res += 1LL * num1[i] * (num1[i] - 1) / 2;
    for (int i = 0; i < n; i++) {
      if (i != U && i != V) {
        mp[{comp[0][i], comp[1][i]}]++;
        s.insert({comp[0][i], comp[1][i]});
      }
    }
    for (auto x : s) {
      long long u = x.first, v = x.second, to = mp[{u, v}];
      res -= 1LL * (to * (to - 1) / 2);
    }
    long long total = 1LL * (n - 2) * (n - 3) / 2;
    cout << total - res << "\n";
    s.clear();
    mp.clear();
    for (int i = 0; i < n; i++) {
      num0[i] = num1[i] = 0;
      comp[1][i] = comp[0][i] = 0;
      mark[0][i] = mark[1][i] = false;
      adj[i].clear();
    }
    cnt = 0, cnt2 = 0;
  }
}
