#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10, MAXM = 2e6 + 10, INF = INT_MAX;
const int MOD = 1e9 + 7, mod = 998244353;
int fa[MAXN];
int _find(int x) { return x ^ fa[x] ? fa[x] = _find(fa[x]) : fa[x]; }
int n, m, a, b;
int vis[MAXN];
int cnt[MAXN];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d%d%d", &n, &m, &a, &b);
    memset(vis, 0, (n + 5) * sizeof(int));
    memset(cnt, 0, (n + 5) * sizeof(int));
    vector<int> av, bv;
    for (int i = 1; i <= n; i++) fa[i] = i;
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      if ((u == a && v == b) || (u == b && v == a)) continue;
      if (u == a || v == a || u == b || v == b) {
        if (u == a) av.push_back(v);
        if (u == b) bv.push_back(v);
        if (v == a) av.push_back(u);
        if (v == b) bv.push_back(u);
        continue;
      }
      int uu = _find(u), vv = _find(v);
      if (uu != vv) fa[uu] = vv;
    }
    int tot = 0;
    for (int i = 1; i <= n; i++) {
      int p = _find(i);
      cnt[p]++;
      if (!vis[p]) {
        vis[p] = 1;
        tot++;
      }
    }
    memset(vis, 0, (n + 5) * sizeof(int));
    if (tot <= 3) {
      puts("0");
      continue;
    }
    for (auto j : av) {
      j = _find(j);
      if (!vis[j]) {
        vis[j] = 1;
      }
    }
    for (auto j : bv) {
      j = _find(j);
      if (vis[j] == 1)
        vis[j] = 3;
      else if (!vis[j])
        vis[j] = 2;
    }
    long long t1 = 0, t2 = 0;
    for (auto j : av) {
      j = _find(j);
      if (vis[j] >= 1 && vis[j] <= 2) {
        vis[j] = 3;
        t1 += cnt[j];
      }
    }
    for (auto j : bv) {
      j = _find(j);
      if (vis[j] >= 1 && vis[j] <= 2) {
        vis[j] = 3;
        t2 += cnt[j];
      }
    }
    printf("%lld\n", t1 * t2);
  }
  return 0;
}
