#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > adjLis;
vector<int> p;
void par(int x) {
  if (p[x] == x) return;
  par(p[x]);
  p[x] = p[p[x]];
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m, a, b;
    scanf("%d%d%d%d", &n, &m, &a, &b);
    a--;
    b--;
    adjLis.assign(n, vector<int>());
    for (int i = 0; i < m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      u--;
      v--;
      adjLis[u].push_back(v);
      adjLis[v].push_back(u);
    }
    p.resize(n);
    for (int i = 0; i < n; i++) p[i] = i;
    for (int i = 0; i < n; i++) {
      if (i == b) continue;
      for (int j = 0; j < adjLis[i].size(); j++) {
        if (adjLis[i][j] == b) continue;
        par(i);
        par(adjLis[i][j]);
        if (p[i] != p[adjLis[i][j]]) {
          p[p[i]] = p[adjLis[i][j]];
        }
      }
    }
    for (int i = 0; i < n; i++) par(i);
    vector<int> loca(n, 0);
    for (int i = 0; i < n; i++) {
      if (p[i] == p[a]) loca[i] += 1;
    }
    for (int i = 0; i < n; i++) p[i] = i;
    for (int i = 0; i < n; i++) {
      if (i == a) continue;
      for (int j = 0; j < adjLis[i].size(); j++) {
        if (adjLis[i][j] == a) continue;
        par(i);
        par(adjLis[i][j]);
        if (p[i] != p[adjLis[i][j]]) {
          p[p[i]] = p[adjLis[i][j]];
        }
      }
    }
    for (int i = 0; i < n; i++) par(i);
    for (int i = 0; i < n; i++) {
      if (p[i] == p[b]) loca[i] += 2;
    }
    loca[a] = loca[b] = 3;
    int ctr1 = 0, ctr2 = 0;
    for (int i = 0; i < n; i++) {
      if (loca[i] == 1) ctr1++;
      if (loca[i] == 2) ctr2++;
    }
    printf("%lld\n", (long long)ctr1 * ctr2);
  }
}
