#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 5;
const int INF = 1e9 + 7;
long long poww(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}
long long MOD(long long a) { return ((a % INF) + INF) % INF; }
int cnt[MAXN], mark[MAXN], n, m, a, b;
bool visited[MAXN];
vector<int> adjList[MAXN];
void dfs(int start, int dest, bool m) {
  ++cnt[start];
  visited[start] = true;
  if (start == dest) return;
  mark[start] = m;
  for (auto u : adjList[start])
    if (!visited[u]) dfs(u, dest, m);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m >> a >> b;
    for (int i = 1; i <= n; ++i)
      adjList[i].clear(), visited[i] = false, cnt[i] = 0, mark[i] = 2;
    for (int i = 0; i < m; ++i) {
      int c, d;
      cin >> c >> d;
      adjList[c].push_back(d);
      adjList[d].push_back(c);
    }
    dfs(a, b, 0);
    for (int i = 1; i <= n; ++i) visited[i] = false;
    dfs(b, a, 1);
    int first = 0, second = 0;
    for (int i = 1; i <= n; ++i) {
      if (cnt[i] == 2) continue;
      if (mark[i] == 0)
        ++first;
      else
        ++second;
    }
    cout << first * 1ll * second << '\n';
  }
}
