#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 5;
struct Edge {
  int u, v;
  Edge() {}
  Edge(int _u, int _v) : u(_u), v(_v) {}
};
struct Graph {
  Edge E[MAXN << 1];
  int head[MAXN], nex[MAXN << 1], cnt;
  void init(int n) {
    cnt = 0;
    memset(head, -1, sizeof(int) * (n + 5));
  }
  void addEdge(int u, int v) {
    E[cnt] = Edge(u, v);
    nex[cnt] = head[u];
    head[u] = cnt++;
  }
};
struct Tarjan : Graph {
  int n;
  int dfn[MAXN], cnt;
  int low[MAXN];
  int siz[MAXN];
  int par[MAXN];
  bool cut[MAXN];
  void init(int _n) {
    n = _n;
    cnt = 0;
    Graph::init(n);
    memset(dfn, 0, sizeof(int) * (n + 5));
    memset(low, 0, sizeof(int) * (n + 5));
    memset(cut, 0, sizeof(int) * (n + 5));
    memset(par, 0, sizeof(int) * (n + 5));
    memset(siz, 0, sizeof(int) * (n + 5));
  }
  void tarjan(int u) {
    dfn[u] = low[u] = ++cnt;
    siz[u] = 1;
    int son = 0;
    for (int i = head[u]; ~i; i = nex[i]) {
      int v = E[i].v;
      if (!dfn[v]) {
        son++;
        par[v] = u;
        tarjan(v);
        low[u] = min(low[u], low[v]);
        siz[u] += siz[v];
        if (dfn[u] <= low[v]) {
          cut[u] = true;
        }
      } else if (dfn[v] < dfn[u] && v != par[u]) {
        low[u] = min(low[u], dfn[v]);
      }
    }
    if (!par[u] && son == 1) {
      cut[u] = false;
    }
  }
  void solve(int rt) {
    par[rt] = 0;
    tarjan(rt);
  }
};
int n, m, a, b;
Tarjan graph;
void init() { graph.init(n); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> m >> a >> b;
    init();
    while (m--) {
      int u, v;
      cin >> u >> v;
      graph.addEdge(u, v);
      graph.addEdge(v, u);
    }
    graph.solve(a);
    int siz = 0;
    for (int i = graph.head[b]; ~i; i = graph.nex[i]) {
      int v = graph.E[i].v;
      if (graph.par[v] == b && graph.dfn[b] <= graph.low[v]) {
        siz += graph.siz[v];
      }
    }
    while (graph.par[b] != a) {
      b = graph.par[b];
    }
    cout << 1LL * (graph.siz[a] - graph.siz[b] - 1) * siz << '\n';
  }
  return 0;
}
