#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const int Mod = 1e9 + 7;
const int N = 2e5 + 100;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
inline long long dpow(long long a, long long b) {
  long long r = 1, t = a;
  while (b) {
    if (b & 1) r = (r * t) % Mod;
    b >>= 1;
    t = (t * t) % Mod;
  }
  return r;
}
inline long long fpow(long long a, long long b) {
  long long r = 1, t = a;
  while (b) {
    if (b & 1) r = (r * t);
    b >>= 1;
    t = (t * t);
  }
  return r;
}
vector<int> G[N];
int n, m, a, b;
bool vis[N], ok;
void Init() {
  for (int i = 1; i <= n; i++) G[i].clear(), vis[i] = false;
}
void DFS(int x, int y, int no, int &cnt) {
  cnt++;
  if (x == no) ok = false;
  vis[x] = true;
  for (auto v : G[x])
    if (v != y && !vis[v]) DFS(v, y, no, cnt);
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    scanf("%d %d %d %d", &n, &m, &a, &b);
    Init();
    for (int i = 0; i < m; ++i) {
      int u, v;
      scanf("%d %d", &u, &v);
      G[u].push_back(v);
      G[v].push_back(u);
    }
    int cnt1 = 0;
    vis[a] = true;
    for (int i = 1; i <= n; ++i) {
      if (vis[i]) continue;
      ok = true;
      int cnt = 0;
      DFS(i, a, b, cnt);
      if (ok) cnt1 += cnt;
    }
    for (int i = 1; i <= n; ++i) vis[i] = false;
    vis[b] = true;
    int cnt2 = 0;
    for (int i = 1; i <= n; ++i) {
      if (vis[i]) continue;
      ok = true;
      int cnt = 0;
      DFS(i, b, a, cnt);
      if (ok) cnt2 += cnt;
    }
    printf("%lld\n", 1ll * cnt1 * cnt2);
  }
  return 0;
}
