#include <bits/stdc++.h>
using namespace std;
vector<int> g[200005];
int t;
int n, m, a, b;
bool visited[200005];
set<int> bbb;
set<int> aaa;
set<int> null;
int par[200005];
bool flag = false;
void dfs(int i, int p) {
  visited[i] = true;
  par[i] = p;
  for (auto it : g[i]) {
    if (!visited[it]) dfs(it, i);
  }
}
void dfs1(int i) {
  if (i == b) return;
  visited[i] = true;
  aaa.insert(i);
  for (auto it : g[i]) {
    if (!visited[it] && (null.find(it) == null.end())) dfs1(it);
  }
}
void dfs2(int i) {
  visited[i] = true;
  bbb.insert(i);
  for (auto it : g[i]) {
    if (aaa.find(it) != aaa.end() && (it != a)) flag = true;
    if (!visited[it] && (null.find(it) == null.end())) dfs2(it);
  }
}
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> m >> a >> b;
    for (int i = 0; i <= n; i++) {
      visited[i] = false;
      par[i] = -1;
      g[i].clear();
    }
    bbb.clear();
    aaa.clear();
    null.clear();
    for (int i = 0; i < m; i++) {
      int u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(a, -1);
    int p = par[b];
    while (p != a) {
      null.insert(p);
      p = par[p];
    }
    for (int i = 0; i <= n; i++) visited[i] = false;
    dfs1(a);
    dfs2(b);
    for (auto it : bbb) {
      for (auto ii : g[it]) {
        if (aaa.find(ii) != aaa.end() && (ii != a)) flag = true;
      }
    }
    if (flag) {
      cout << 0 << "\n";
      continue;
    }
    int x = aaa.size();
    int y = bbb.size();
    x--;
    y--;
    cout << x * y << "\n";
  }
}
