#include <bits/stdc++.h>
using namespace std;
                        
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long

int n, m, a, b;
vector<vector<int> > g;
vector<bool> vis;
vector<int> comp; 
vector<int> sz;

int group = 0, cnt = 0;

void dfs(int u) {
    cnt++;
    vis[u] = true;
    comp[u] = group;
    for (int v : g[u]) {
        if (!vis[v] && (v != a && v != b)) 
            dfs(v);
    }
}

void solve() {
    cin >> n >> m >> a >> b;
    cnt = 0;
    group = 0;
    g.clear();
    g.resize(n + 5);
    vis.clear();
    vis.resize(n + 5, false);
    comp.clear();
    comp.resize(n + 5);
    sz.clear();
    sz.resize(n + 5, 0);
    for (int i = 0, u, v; i < m; i++) {
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    for (int i = 1; i <= n; i++) {
        if (!vis[i] && i != a && i != b) {
            group++;
            cnt = 0;
            dfs(i);
            sz[group] = cnt; 
        }
    }
    if (group == 1) {
        cout << 0 << endl;
        return;
    }
    set<int> s1, s2;
    for (int v : g[a])
        s1.insert(comp[v]);
    for (int v : g[b])
        s2.insert(comp[v]);
    int mark[group+ 5] = {0};
    for (int x : s1)
        mark[x]++;
    for (int x : s2)
        mark[x]++;
    vector<int> vec;
    int total = 0;
    for (int i = 1; i <= group; i++) {
        if (mark[i] == 1)
            vec.push_back(i), total += sz[i];
    }       
    int ans = 0;
    for (int x : vec) {
        ans += (total - sz[x]) * sz[x];
    }

    ans >>= 1;
    cout << ans << endl;

}
                
int32_t main() {
    fast_cin();  
        
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
 
 
    return 0;
}