#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long
//#define d double
#define F first
#define S second
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(10)
const int M=1e9+7;
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)

void dfs(int s,int nt,vector<int>adj[],int visited[])
{
    if(s==nt)
        return;
    visited[s]=1;

    for(int x:adj[s])
    {
        if(!visited[x] && x!=nt)dfs(x,nt,adj,visited);
    }
}

int main()
{
    T()
    {
        int n,m,a,b,x,y;
        cin>>n>>m>>a>>b;

        vector<int>adj[n+1];

        for(int i=0;i<m;i++)
        {
            cin>>x>>y;
            adj[x].pb(y);
            adj[y].pb(x);
        }
        int visited[n+1]={0};
        dfs(a,b,adj,visited);
        long ra=0,rb=0;
        for(int i=1;i<=n;i++)
        if(!visited[i])ra++;

        memset(visited,0,sizeof(visited));
        dfs(b,a,adj,visited);

        for(int i=1;i<=n;i++)
            if(!visited[i])
            rb++;
        long ans=(ra-1)*(rb-1);
        cout<<ans<<endl;
    }
}
