#include <bits/stdc++.h>
using namespace std;
set<long long int> blacklist;
long long int par(long long int* parent, long long int f, long long int n) {
  if (parent[f] < 0) return parent[f];
  if (parent[f] == f)
    return f;
  else {
    parent[f] = par(parent, parent[f], n);
    return parent[f];
  }
}
void unio(long long int* parent, long long int f, long long int s,
          long long int pf, long long int ps) {
  if (pf < ps)
    parent[ps] = pf;
  else
    parent[pf] = ps;
}
void utilfun(long long int* parent, vector<long long int>* adj,
             pair<long long int, long long int>* edge, long long int n,
             long long int m, long long int a, long long int b) {
  for (long long int i = 0; i < m; i++) {
    long long int f = edge[i].first;
    long long int s = edge[i].second;
    if (f == a || f == b || s == a || s == b) {
      continue;
    } else {
      long long int pf = par(parent, f, n);
      long long int ps = par(parent, s, n);
      unio(parent, f, s, pf, ps);
    }
  }
  long long int ind = -2;
  for (long long int i = 0; i < m; i++) {
    long long int f = edge[i].first;
    long long int s = edge[i].second;
    if ((f == a || s == a) && (s != b && f != b)) {
      long long int ot = f + s - a;
      long long int pot = par(parent, ot, n);
      if (pot >= 0) {
        parent[pot] = ind;
        ind--;
      }
    }
  }
  for (long long int i = 0; i < m; i++) {
    long long int f = edge[i].first;
    long long int s = edge[i].second;
    if ((f == b || s == b) && (s != a && f != a)) {
      long long int ot = f + s - b;
      long long int pot = par(parent, ot, n);
      if (pot == -1) {
        continue;
      } else if (pot < -1) {
        blacklist.insert(pot);
      } else
        parent[pot] = b;
    }
  }
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    blacklist.clear();
    long long int n, m, a, b;
    cin >> n >> m >> a >> b;
    a--;
    b--;
    vector<long long int> adj[n];
    pair<long long int, long long int> edge[m];
    long long int parent[n];
    for (long long int i = 0; i < n; i++) parent[i] = i;
    for (long long int i = 0; i < m; i++) {
      long long int x, y;
      cin >> x >> y;
      x--;
      y--;
      adj[x].push_back(y);
      adj[y].push_back(x);
      edge[i] = {x, y};
    }
    utilfun(parent, adj, edge, n, m, a, b);
    long long int ac = 0;
    long long int bc = -1;
    set<long long int>::iterator itr;
    for (long long int i = 0; i < n; i++) {
      long long int pot = par(parent, i, n);
      if (blacklist.find(pot) != blacklist.end()) continue;
      if (pot < -1)
        ac++;
      else if (pot == b)
        bc++;
    }
    cout << ac * bc << "\n";
  }
}
