#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;
void dfs1(int i) {
  visited[i] = true;
  aaa.insert(i);
  if (i == b) return;
  for (auto it : g[i]) {
    if (!visited[it]) dfs1(it);
  }
}
void dfs2(int i) {
  visited[i] = true;
  bbb.insert(i);
  for (auto it : g[i])
    if (!visited[it]) dfs2(it);
}
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> m >> a >> b;
    for (int i = 0; i <= n; i++) {
      visited[i] = false;
      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);
    }
    dfs1(a);
    bool flag = false;
    for (auto it : g[b]) {
      if (it == a) continue;
      if (visited[it])
        null.insert(it);
      else
        flag = true;
    }
    if (!flag) {
      cout << 0 << "\n";
      continue;
    }
    dfs2(b);
    for (auto it : bbb) {
      if (aaa.find(it) != aaa.end()) aaa.erase(it);
    }
    for (auto it : null) {
      if (aaa.find(it) != aaa.end()) aaa.erase(it);
    }
    int x = aaa.size();
    int y = bbb.size();
    x--;
    y--;
    cout << x * y << "\n";
  }
}
