#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, head[200010], num, from, to, T;
int read() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return x;
}
struct xx {
  int next, to;
} way[1000010];
void add(int from, int to) {
  way[++num].next = head[from];
  way[num].to = to;
  head[from] = num;
}
int dfn[200010], s, c[200010], size[200010], t, o, low[200010];
vector<int> v;
void dfs(int x, int fa, int d, int op) {
  size[d]++;
  c[x] = d;
  low[x] = dfn[x] = ++t;
  if (op) v.push_back(x);
  if (op)
    if (fa != o) low[x] = min(low[x], low[fa]);
  for (int i = head[x]; i; i = way[i].next) {
    int y = way[i].to;
    if (y == fa) continue;
    if (!dfn[y]) {
      if (x == o)
        dfs(y, x, d, 1);
      else
        dfs(y, x, d, op);
      low[x] = min(low[x], low[y]);
    } else
      low[x] = min(low[x], dfn[y]);
  }
}
int main() {
  T = read();
  while (T--) {
    v.clear();
    n = read();
    m = read();
    x = read();
    y = read();
    for (int i = 1; i <= n; ++i) head[i] = 0;
    num = 0;
    for (int i = 1; i <= m; ++i) {
      from = read();
      to = read();
      add(from, to);
      add(to, from);
    }
    dfn[x] = 1;
    t = 1;
    int co = 0;
    o = y;
    for (int i = head[x]; i; i = way[i].next) {
      int y = way[i].to;
      co++;
      dfs(y, x, co, 0);
    }
    int g = n - 1 - size[c[y]];
    long long ans = 0;
    for (int i = 0; i < (int)v.size(); ++i)
      if (low[v[i]] >= dfn[y]) ans += g;
    printf("%lld\n", ans);
    for (int i = 1; i <= co; ++i) size[i] = 0;
    for (int i = 1; i <= n; ++i) dfn[i] = low[i] = 0;
  }
  return 0;
}
