#include <bits/stdc++.h>
inline long long read() {
  long long x = 0;
  char c = getchar(), f = 1;
  for (; c < '0' || '9' < c; c = getchar())
    if (c == '-') f = -1;
  for (; '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
inline void write(long long x) {
  static char buf[20];
  int len = 0;
  if (x < 0) putchar('-'), x = -x;
  for (; x; x /= 10) buf[len++] = x % 10 + '0';
  if (!len)
    putchar('0');
  else
    while (len) putchar(buf[--len]);
}
inline void writesp(long long x) {
  write(x);
  putchar(' ');
}
inline void writeln(long long x) {
  write(x);
  putchar('\n');
}
int x[500010], y[500010];
int fa[500010];
int n, m, p, q;
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void work() {
  n = read();
  m = read();
  p = read();
  q = read();
  for (int i = 1; i <= m; i++) x[i] = read(), y[i] = read();
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++)
    if (x[i] != p && y[i] != p) fa[find(x[i])] = find(y[i]);
  int cntp = 0;
  for (int i = 1; i <= n; i++)
    if (i != p && find(i) != find(q)) ++cntp;
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++)
    if (x[i] != q && y[i] != q) fa[find(x[i])] = find(y[i]);
  int cntq = 0;
  for (int i = 1; i <= n; i++)
    if (i != q && find(i) != find(p)) ++cntq;
  writeln((long long)cntp * cntq);
}
int main() {
  int T = read();
  while (T--) work();
  return 0;
}
