//                                  .........
//                           .... ............. ....
//                       ...      .............      ..
//                     ..          ...........         ...
//                    ..                                ...
//                    ..                                ...
//                   ..                                 ...
//                   ..                                 ...
//                   ..             mohit1O98           . ..
//                   .. .                                 ..
//                   ..                                   ..
//                  ...                                   ..
//                  ... .....                       ....  ...
//                  ......  .......................... ......
//                  ..  ...      ..          ..       ...  ..
//                  ..                                     ..
//                  .                                      ..
//                  ..                                     ..
//                  ...                                  ....
//                  .....   .                       .   ....
//                   .....   ..                   .    ....
//                    ......   .                ..   .....
//                     ......   .              ..   ......
//                      ......   .            .    ......
//                       .....    .............    .....
//                       .........             ........
//                        ...      .         .     ....
//                         ....   .............   ...
//                            ....................
//

#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
using namespace std;

//g++-9 -Wl,-stack_size -Wl,100000000 test.cpp -o test
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//#define INFF 9223372036854775807
#define INF 1000000000000000001

#define debug1 cout<<"helo 1"<<endl;
#define debug2 cout<<"helo 2"<<endl;
#define endl "\n"
#define couti(a) printf("%d ",a)
#define coutl(a) printf("%lld ",a)
#define nline printf("\n")
#define cini(a) scanf("%d",&a)
#define cinl(a) scanf("%lld",&a)

#define mp make_pair
#define f first
#define pb push_back
#define pob pop_back
#define s second
#define t third

#define int long long
#define ll long long
#define LL long long

//#define PI 3.14159265

#define priorqmax priority_queue<LL>
#define priorqmin priority_queue<LL,vector<LL>,greater<LL> >
#define len length()
#define vi vector<int>
#define vl vector<ll>
#define ve vector
#define lsti list<int>
#define pairi pair<int,int>
#define pairl pair<ll,ll>
#define mset(a) memset(a,0,sizeof(a))
#define FOR(j,a,n) for(int j=a;j<n;++j)
#define FOR1(j,a,n) for(int j=a;j>=n;--j)


class comp_ordered_set_pair{
public:
   bool operator() (const pairi &a,const pairi &b) const{
      if(a.f==b.f)
         return a.s<b.s;
      return a.f<b.f;
   }
};
typedef tree<
   pairi,
   null_type,
   comp_ordered_set_pair,
   rb_tree_tag,
   tree_order_statistics_node_update>
   ordered_set_pair;

class trio{public: int first,second, third;};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// ifstream iFile("input.txt");
// ofstream oFile("output.txt");

//#define MOD 1000000007
//#define MOD 987654319
#define MOD 998244353


ll gcdExtended(ll a, ll b, ll *x, ll *y){
   if (a == 0){
      *x = 0, *y = 1;
      return b;
   }
   ll x1, y1;
   ll gcd = gcdExtended(b%a, a, &x1, &y1);
   *x = y1 - (b/a) * x1;
   *y = x1;
   return gcd;
}
ll modInverse(ll a, ll m){
   ll x, y;
   ll g = gcdExtended(a, m, &x, &y);
   ll res = (x%m + m) % m;
   return res;
}

LL power(LL x,LL y){
   //(x^y)%MOD
   LL ans=1,s=x;
   while(y){
      if(y&1){
         ans*=s;
         ans%=MOD;
      }
      s*=s;
      s%=MOD;
      y>>=1;
   }
   return ans;
}

// .................................................. START
// Check if int needs to be converted to long long  _/\_
int a,b;
ve<lsti>adj;
vi visited;

bool fl=0;

int dfs(int i,int id){
   if(id==1){
      if(i==a)
         return 0;
      if(i==b)
         fl=1;
   }
   else if(id==2){
      if(i==b)
         return 0;
      if(i==a)
         fl=1;
   }
   else{
      if(i==a || i==b)
         return 0;
   }
   if(visited[i])
      return 0;
   
   int sum=1;
   visited[i]=1;
   for(auto it:adj[i]){
      sum+=dfs(it,id);
   }
   return sum;
}

int32_t main(){
   fastio;
   
   int t;
   cin>>t;
   
   while(t--) {
      
      int n,u,v;
      cin>>n;
      
      adj.assign(n+1,lsti());
      
      int m;
      cin>>m>>a>>b;
      
      FOR(i,0,m){
         cin>>u>>v;
         adj[u].pb(v);
         adj[v].pb(u);
      }
      
      int a1=0,a2=0,a3=0;
      
      visited.assign(n+1,0);
      int ver=0;
      FOR(i,1,n+1){
         if(!visited[i]){
            int temp = dfs(i,1);
   
            if(fl){
               temp--;
               fl=0;
            }
            a1+=ver*temp;
            ver+=temp;
            
            
         }
      }
   
      visited.assign(n+1,0);
      ver=0;
      FOR(i,1,n+1){
         if(!visited[i]){
            int temp = dfs(i,2);
            if(fl){
               temp--;
               fl=0;
            }
            a2+=ver*temp;
            ver+=temp;
         }
      }
   
      visited.assign(n+1,0);
      ver=0;
      FOR(i,1,n+1){
         if(!visited[i]){
            int temp = dfs(i,3);
            a3+=ver*temp;
            ver+=temp;
         }
      }
//      cout<<a1<<" "<<a2<<" "<<a3<<endl;
      cout<<a1+a2-a3<<endl;
   
   }
   
   

   return 0;
}
