#include <bits/stdc++.h>
using namespace std;
const int N = 200010, M = 500010;
int h[N], e[M * 2], nex[M * 2], idx, n, m, nodea, nodeb, sz;
int col[N];
void add(int x, int y) {
  e[idx] = y;
  nex[idx] = h[x];
  h[x] = idx++;
}
bool dfs1(int u) {
  col[u] = 1;
  sz++;
  for (int i = h[u]; ~i; i = nex[i]) {
    int v = e[i];
    if (v == nodea) continue;
    if (v == nodeb || col[v] == 2) return false;
    if (col[v] == 0) {
      if (!dfs1(v)) return false;
    }
  }
  return true;
}
bool dfs2(int u) {
  col[u] = -1;
  sz++;
  for (int i = h[u]; ~i; i = nex[i]) {
    int v = e[i];
    if (v == nodeb) continue;
    if (v == nodea || col[v] == 1 || col[v] == 2) return false;
    if (col[v] == 0) {
      if (!dfs2(v)) return false;
    }
  }
  return true;
}
void modify(int u) {
  col[u] = 2;
  for (int i = h[u]; ~i; i = nex[i]) {
    int v = e[i];
    if (col[v] == 2 || v == nodea || v == nodeb)
      continue;
    else
      modify(v);
  }
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    scanf("%d%d%d%d", &n, &m, &nodea, &nodeb);
    for (int i = 0; i <= n; ++i) h[i] = -1, col[i] = 0;
    idx = 0;
    for (int i = 1; i <= m; ++i) {
      int x, y;
      scanf("%d%d", &x, &y);
      add(x, y);
      add(y, x);
    }
    int cnta = 0, cntb = 0;
    for (int i = h[nodea]; ~i; i = nex[i]) {
      int v = e[i];
      sz = 0;
      if (col[v] == 0 && v != nodeb) {
        if (dfs1(v))
          cnta += sz;
        else
          modify(v);
      }
    }
    for (int i = h[nodeb]; ~i; i = nex[i]) {
      int v = e[i];
      sz = 0;
      if (col[v] == 0 && v != nodea) {
        if (dfs2(v))
          cntb += sz;
        else
          modify(v);
      }
    }
    cout << 1ll * cnta * cntb << endl;
  }
  return 0;
}
