#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int uf_p[2][N], uf_s[2][N];
int z[N];
vector<int> g1[N];
int uf_get(int x, int y) {
  if (uf_p[y][x] == x) return x;
  return uf_p[y][x] = uf_get(uf_p[y][x], y);
}
void uf_join(int a, int b, int y) {
  a = uf_get(a, y);
  b = uf_get(b, y);
  if (a == b) return;
  if (uf_s[y][b] > uf_s[y][a]) swap(a, b);
  uf_s[y][a] += uf_s[y][b];
  uf_p[y][b] = a;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int ti = 0; ti < t; ++ti) {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    a--;
    b--;
    for (int i = 0; i < n; ++i) {
      uf_p[0][i] = uf_p[1][i] = i;
      uf_s[0][i] = uf_s[1][i] = 1;
      z[i] = 0;
      g1[i].clear();
    }
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      u--;
      v--;
      if (u != a && v != a) {
        uf_join(u, v, 0);
      }
      if (u != b && v != b) {
        uf_join(u, v, 1);
      }
    }
    for (int i = 0; i < n; ++i) {
      if (i == a || i == b) continue;
      int og0 = uf_get(i, 0);
      int og1 = uf_get(i, 1);
      g1[og0].push_back(og1);
      z[og1]++;
    }
    long long res = 0;
    for (int i = 0; i < n; ++i) {
      int oth = (n - 2) - g1[i].size();
      for (int j : g1[i]) z[j]--;
      for (int j : g1[i]) {
        res += oth - z[j];
      }
      for (int j : g1[i]) z[j]++;
    }
    cout << res / 2 << "\n";
  }
}
