#include <bits/stdc++.h>
using namespace std;
namespace io {
const int SI = 1 << 21 | 1;
char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
int f, t;
inline void flush() { fwrite(OB, 1, OS - OB, stdout), OS = OB; }
inline void pc(char x) {
  *OS++ = x;
  if (OS == OT) flush();
}
template <class I>
inline void rd(I &x) {
  for (f = 1, c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                              IS == IT ? EOF : *IS++)
                            : *IS++);
       c < '0' || c > '9';
       c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                       IS == IT ? EOF : *IS++)
                     : *IS++))
    if (c == '-') f = -1;
  for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15),
      c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                      IS == IT ? EOF : *IS++)
                    : *IS++))
    ;
  x *= f;
}
inline void rds(char *s, int &x) {
  for (c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                       IS == IT ? EOF : *IS++)
                     : *IS++);
       c < 33 || c > 126;
       c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                       IS == IT ? EOF : *IS++)
                     : *IS++))
    ;
  for (x = 0; c >= 33 && c <= 126;
       s[++x] = c, c = (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin),
                                   IS == IT ? EOF : *IS++)
                                 : *IS++))
    ;
  s[x + 1] = '\0';
}
template <class I>
inline void print(I x, char k = '\n') {
  if (!x) pc('0');
  if (x < 0) pc('-'), x = -x;
  while (x) ch[++t] = x % 10 + '0', x /= 10;
  while (t) pc(ch[t--]);
  pc(k);
}
inline void prints(string s) {
  int x = s.length();
  while (t < x) pc(s[t++]);
  pc('\n'), t = 0;
}
struct Flush {
  ~Flush() { flush(); }
} flusher;
}  // namespace io
using io::print;
using io::prints;
using io::rd;
using io::rds;
const int N = 2e5 + 7;
int n, m, a, b, v[N];
vector<int> e[N];
void dfs(int x, int z) {
  v[x] = 1;
  for (unsigned int i = 0; i < e[x].size(); i++) {
    int y = e[x][i];
    if (v[y] || y == z) continue;
    dfs(y, z);
  }
}
inline void solve() {
  rd(n), rd(m), rd(a), rd(b);
  for (int i = 1; i <= n; i++) e[i].clear();
  for (int i = 1, x, y; i <= m; i++)
    rd(x), rd(y), e[x].push_back(y), e[y].push_back(x);
  int c = 0, d = 0;
  for (int i = 1; i <= n; i++) v[i] = 0;
  dfs(a, b);
  for (int i = 1; i <= n; i++) c += !v[i];
  for (int i = 1; i <= n; i++) v[i] = 0;
  dfs(b, a);
  for (int i = 1; i <= n; i++) d += !v[i];
  print(1ll * (c - 1) * (d - 1));
}
int main() {
  int T;
  rd(T);
  while (T--) solve();
  return 0;
}
