#include <bits/stdc++.h>
using namespace std;
int n, m, s, t;
namespace Tree {
const int N = 2e6;
struct Edge {
  int v, nxt;
} e[(N << 1) + 3];
int fe[N + 3];
int fa[N + 3];
int sz[N + 3];
int a[N + 3];
int n, en;
void addedge(int u, int v) {
  en++;
  e[en].v = v;
  e[en].nxt = fe[u];
  fe[u] = en;
}
void dfs(int u) {
  sz[u] = a[u];
  for (int i = fe[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa[u]) continue;
    fa[v] = u;
    dfs(v);
    sz[u] += sz[v];
  }
}
void solve() {
  dfs(s);
  int u = t;
  while (fa[u] != s) {
    u = fa[u];
  }
  long long ans = (::n - sz[u] - 1ll) * (sz[t] - 1ll);
  printf("%I64d\n", ans);
}
void clear() {
  for (int i = 1; i <= en; i++) e[i].v = e[i].nxt = 0;
  for (int i = 1; i <= n; i++) fa[i] = fe[i] = sz[i] = a[i] = 0;
  n = en = 0;
}
}  // namespace Tree
namespace Graph {
const int N = 1e6;
const int M = 4e6;
struct Edge {
  int v, nxt;
} e[(M << 1) + 3];
int fe[N + 3];
int fa[N + 3];
int dfn[N + 3], low[N + 3], stk[N + 3];
int n, en, cnt, tp;
void addedge(int u, int v) {
  en++;
  e[en].v = v;
  e[en].nxt = fe[u];
  fe[u] = en;
}
void Tarjan(int u) {
  cnt++;
  dfn[u] = low[u] = cnt;
  tp++;
  stk[tp] = u;
  for (int i = fe[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa[u]) continue;
    if (!dfn[v]) {
      fa[v] = u;
      Tarjan(v);
      low[u] = min(low[u], low[v]);
      if (low[v] >= dfn[u]) {
        Tree::n++;
        Tree::addedge(u, Tree::n);
        Tree::addedge(Tree::n, u);
        while (tp > 0) {
          Tree::addedge(Tree::n, stk[tp]);
          Tree::addedge(stk[tp], Tree::n);
          tp--;
          if (stk[tp + 1] == v) {
            break;
          }
        }
      }
    } else {
      low[u] = min(low[u], dfn[v]);
    }
  }
}
void buildTree() {
  Tree::n = n;
  for (int i = 1; i <= n; i++) Tree::a[i] = 1;
  for (int i = 1; i <= n; i++) {
    if (!dfn[i]) {
      Tarjan(i);
    }
  }
}
void clear() {
  for (int i = 1; i <= en; i++) e[i].v = e[i].nxt = 0;
  for (int i = 1; i <= n; i++) fe[i] = fa[i] = dfn[i] = low[i] = stk[i] = 0;
  n = en = cnt = tp = 0;
}
}  // namespace Graph
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d%d%d", &n, &m, &s, &t);
    Graph::n = n;
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      Graph::addedge(u, v);
      Graph::addedge(v, u);
    }
    Graph::buildTree();
    Tree::solve();
    Graph::clear();
    Tree::clear();
  }
  return 0;
}
