#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
vector<int> adj[400001];
bool visited[400001];
long long int cnt;
void dfs(int v, int x) {
  cnt++;
  visited[v] = 1;
  for (int i = 0; i < adj[v].size(); i++) {
    if (adj[v][i] == x) continue;
    if (!visited[adj[v][i]]) dfs(adj[v][i], x);
  }
}
int main() {
  int t, x, y;
  cin >> t;
  while (t--) {
    cin >> n >> m >> a >> b;
    for (int i = 1; i <= n; i++) {
      visited[i] = 0;
      adj[i].clear();
    }
    for (int i = 1; i <= m; i++) {
      cin >> x >> y;
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    long long int cnt1 = 0, cnt2 = 0;
    cnt = 0;
    dfs(a, b);
    cnt1 = n - 1 - cnt;
    for (int i = 1; i <= n; i++) visited[i] = 0;
    cnt = 0;
    dfs(b, a);
    cnt2 = n - 1 - cnt;
    cout << cnt1 * cnt2 << "\n";
  }
}
