#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
vector<long long> adj[200003];
vector<bool> visited;
long long a, b;
long long cnt = 0;
void dfs(long long s) {
  if (!visited[s]) {
    visited[s] = true;
    cnt++;
    for (auto x : adj[s]) {
      dfs(x);
    }
  }
}
void dfs_a(long long s) {
  if (!visited[s]) {
    visited[s] = true;
    if (s != b) {
      cnt++;
    }
    for (auto x : adj[s]) {
      dfs_a(x);
    }
  }
}
void dfs_b(long long s) {
  if (!visited[s]) {
    visited[s] = true;
    if (s != a) {
      cnt++;
    }
    for (auto x : adj[s]) {
      dfs_b(x);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, i, j, k, t, temp;
  long long tc;
  cin >> tc;
  while (tc--) {
    long long m;
    cin >> n >> m >> a >> b;
    visited.clear();
    visited.resize(n + 1);
    long long tot = 0;
    tot = (n - 2) * (n - 3);
    tot /= 2;
    for (i = 1; i <= n; i++) {
      adj[i].clear();
    }
    for (i = 1; i <= m; i++) {
      cin >> j >> k;
      adj[j].push_back(k);
      adj[k].push_back(j);
    }
    long long ans_a = 0, ans_b = 0, ans_ab = 0;
    for (i = 1; i <= n; i++) {
      visited[i] = false;
    }
    visited[a] = true;
    for (i = 1; i <= n; i++) {
      if (!visited[i]) {
        cnt = 0;
        dfs_a(i);
        ans_a += (cnt * (cnt - 1)) / 2;
      }
    }
    for (i = 1; i <= n; i++) {
      visited[i] = false;
    }
    visited[b] = true;
    for (i = 1; i <= n; i++) {
      if (!visited[i]) {
        cnt = 0;
        dfs_b(i);
        ans_b += (cnt * (cnt - 1)) / 2;
      }
    }
    for (i = 1; i <= n; i++) {
      visited[i] = false;
    }
    visited[a] = true;
    visited[b] = true;
    for (i = 1; i <= n; i++) {
      if (!visited[i]) {
        cnt = 0;
        dfs(i);
        ans_ab += (cnt * (cnt - 1)) / 2;
      }
    }
    tot = tot - ans_a - ans_b + ans_ab;
    cout << tot << endl;
  }
  return 0;
}
