#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
vector<int> adj[200007];
bool v[200007];
bool k[200007];
bool touch[200007];
bool flag;
bool DFS(int x, int p) {
  if (v[x]) return touch[x];
  if (1 != 0 && 0 == 1) printf("from %d >>> now %d\n", p, x);
  v[x] = 1;
  k[x] = 1;
  for (auto y : adj[x]) {
    if (k[y]) continue;
    if (DFS(y, x)) {
      flag = 1;
      touch[x] = 1;
    }
  }
  k[x] = 0;
  return touch[x];
}
int main() {
  int i, j;
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d %d %d", &n, &m, &a, &b);
    for (i = 1; i <= n; i++) adj[i].clear();
    for (i = 0; i < m; i++) {
      int u, v;
      scanf("%d %d", &u, &v);
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    long long int cnt1 = 0;
    long long int cnt2 = 0;
    flag = 0;
    memset(v, 0, n + 1);
    memset(touch, 0, n + 1);
    v[b] = 1;
    touch[b] = 1;
    DFS(a, a);
    for (i = 1; i <= n; i++) {
      if (v[i] && !touch[i]) cnt1++;
    }
    if (1 != 0 && 0 == 1) printf("\n");
    memset(v, 0, n + 1);
    memset(touch, 0, n + 1);
    v[a] = 1;
    touch[a] = 1;
    DFS(b, b);
    for (i = 1; i <= n; i++) {
      if (v[i] && !touch[i]) cnt2++;
    }
    if (1 != 0 && 0 == 1) {
      printf(">>> %lld %lld\n", cnt1, cnt2);
    }
    if (flag)
      printf("%lld\n", cnt1 * cnt2);
    else
      printf("0\n");
  }
  return 0;
}
