//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 1000000007;
const int N = int(3e5) + 999;
#define int long long int

vector<vector<int>>g;
vector<int> visa,visb;
set<int> st;
void bfsa(int node){
	queue<int> q;
	q.push(node);
	visa[node]=1;
	while(!q.empty()){
		int f = q.front();
		q.pop();
		for(auto it:g[f]){
			if(visa[it]==0){
				visa[it]=visa[f]+1;
				q.push(it);
			}
		}
	}
}

void bfsb(int node){
	queue<int> q;
	q.push(node);
	visb[node]=1;
	while(!q.empty()){
		int f = q.front();
		q.pop();
		for(auto it:g[f]){
			if(visb[it]==0){
				visb[it]=visb[f]+1;
				q.push(it);
			}
		}
	}
}


int32_t main(){
    IOS;	
    int tc;
    cin>>tc;
    while(tc--){
    	int n,m,a,b;
    	cin>>n>>m>>a>>b;
    	g.resize(n+1,std::vector<int> (0));
    	visa.resize(n+1,0);
    	visb.resize(n+1,0);
    	st.clear();
    	for(int i=0;i<m;i++){
    		int x,y;cin>>x>>y;
    		g[x].pb(y);
    		g[y].pb(x);
    	}
    	int c1 = 0,c2=0;
    	bfsa(a);
    	bfsb(b);
    	for(int i=1;i<=n;i++){
    		if(i==a or i==b)
    			continue;
    		if(visa[i]>visa[b])
    			c1++;
    	}
    	for(int i=1;i<=n;i++){
    		if(i==a or i==b)
    			continue;
    		if(visb[i]>visb[a])
    			c2++;
    	}
    	cout<<c1*c2<<endl;
    	g.clear();
    	visb.clear();
    	visa.clear();
    }


    return 0;
}