#include <bits/stdc++.h>
using namespace std;
ifstream f("1.in");
int n, m, a, b, t;
int da[200050], db[200050];
bool seen[200050], used[200050];
vector<int> v[200050];
long long ans[3];
void init() {
  for (int i = 1; i <= n; i++) used[i] = 0;
}
void bfs(int st, int d[]) {
  queue<int> Q;
  for (int i = 1; i <= n; i++) used[i] = 0, d[i] = 0x3f3f3f3f;
  used[st] = 1;
  d[st] = 0;
  Q.push(st);
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (auto y : v[x]) {
      if (used[y] == 1) continue;
      if (d[y] >= d[x] + 1) {
        d[y] = d[x] + 1;
        Q.push(y);
      }
    }
  }
}
void dfs(int x, int fara, int unde) {
  ans[unde]++;
  used[x] = 1;
  for (auto y : v[x]) {
    if (y == fara) continue;
    if (used[y] == 1) continue;
    dfs(y, fara, unde);
  }
}
int main() {
  cin >> t;
  while (t--) {
    ans[1] = ans[2] = 0;
    cin >> n >> m >> a >> b;
    for (int i = 1; i <= n; i++) da[i] = db[i] = seen[i] = 0;
    for (int i = 1; i <= n; i++) v[i].clear();
    init();
    int x, y;
    while (m--) {
      cin >> x >> y;
      v[x].push_back(y);
      v[y].push_back(x);
    }
    bfs(a, da);
    bfs(b, db);
    for (int i = 1; i <= n; i++)
      if (da[i] + db[i] == da[b]) {
        seen[i] = 1;
      }
    for (int i = 1; i <= n; i++)
      if (seen[i] == 0 && da[i] < db[i] && used[i] == 0) {
        dfs(i, a, 1);
      }
    init();
    for (int i = 1; i <= n; i++)
      if (seen[i] == 0 && db[i] < da[i] && used[i] == 0) {
        dfs(i, b, 2);
      }
    cout << ans[1] * ans[2] << '\n';
  }
  return 0;
}
