#include <bits/stdc++.h>
using namespace std;
int m, n, b, a;
vector<int> adj[500002];
bool vis[500002];
void dfs(int start) {
  queue<int> q;
  q.push(start);
  vis[start] = true;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto i : adj[u]) {
      if (i == b || vis[i]) continue;
      vis[i] = true;
      q.push(i);
    }
  }
}
void dfs2(int start) {
  queue<int> q;
  q.push(start);
  vis[start] = true;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto i : adj[u]) {
      if (i == a || vis[i]) continue;
      vis[i] = true;
      q.push(i);
    }
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d %d %d", &n, &m, &a, &b);
    for (int i = 0; i <= n; i++) adj[i].clear(), vis[i] = false;
    while (m--) {
      int u, v;
      scanf("%d %d", &u, &v);
      adj[v].push_back(u);
      adj[u].push_back(v);
    }
    dfs(a);
    long long int one = 0, two = 0;
    for (int i = 1; i <= n; i++) {
      if (!vis[i] && i != b) {
        one++;
      }
      vis[i] = false;
    }
    dfs2(b);
    for (int i = 1; i <= n; i++) {
      if (!vis[i] && i != a) two++;
    }
    long long ans = one * two;
    printf("%lld\n", (ans));
  }
}
