import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.HashSet;

public class Main
{
	static int p[] ,n ,a ,b ;	static long wt[] ;
	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);
 
 		ArrayList<HashSet<Integer>> g_ =new ArrayList<>() ,g =new ArrayList<>() ;
 		int t =fr.nextInt() ,m ,i ,j ;	long cnt ,dm ;

 		while (t-- > 0) {
 			n =fr.nextInt() ;	m =fr.nextInt() ;	a =fr.nextInt()-1 ;	b =fr.nextInt()-1 ;
 			for (i =0 ; i<n ; ++i)	{	g.add(new HashSet<>()) ;g_.add(new HashSet<>()) ;	}
 			while (m-- > 0) {
 				i =fr.nextInt()-1 ;	j =fr.nextInt()-1 ;
 				if (i>j)	{	i^=j ;	j^=i ;	i^=j ;	}
 				g.get(i).add(j) ;
 			}

 			for (i =0 ; i<n ; ++i)	g_.get(i).addAll(g.get(i)) ;
 			for (i =0 ; i<a ; ++i)	g_.get(i).remove(a) ;
 			g_.get(a).clear() ;
 			dm =find (g_) ;

 			for (i =0 ; i<n ; ++i)	g_.get(i).addAll(g.get(i)) ;
 			for (i =0 ; i<b ; ++i)	g_.get(i).remove(b) ;
 			g_.get(b).clear() ;
 			dm += find (g_) ;

			for (i =0 ; i<a ; ++i)	g_.get(i).remove(a) ;
 			g_.get(a).clear() ;
 			cnt =dm - find (g_) ;	dm =n-2l ;	dm*=(dm-1l) ;	dm/=2l ;
 			cnt =Math.max(dm-cnt , 0l) ;			
 			op.println(cnt) ;	g.clear() ;g_.clear() ;
 		}
		op.flush();	op.close();
	}
	static long find (ArrayList<HashSet<Integer>> g) {
		init () ;	int i ,k ;	HashSet<Integer> r =new HashSet<>() ;
		long vl =0l ,j ;
		
		for (i =0 ; i<n ; ++i) {
			for (int l : g.get(i)) {
				un (i,l) ;
			}
		}
		for (i =0 ; i<n ; ++i) {
			if (!r.contains(p[i])) {
				k =p[i] ;	r.add(k) ;	//System.out.println(k+" "+wt[k]) ;
				if (k==p[a] || k==p[b])	j =wt[k]-1 ;	else 	j =wt[k] ;
				vl += (j*(j-1l))/2l ;
			}
		}//System.out.println(r) ;
		return vl ;
	}
	static void init () {
		p =new int[n] ;	wt =new long[n] ;
		for (int i =0 ; i<n ; ++i) {
			p[i] =i ;	wt[i] =1l ;
		}
	}
	static void un (int x , int y) {
		x =rt (x) ;	y =rt (y) ;
		if (x!=y) {
			if (wt[x]<wt[y]) {
				p[x] =y ;	wt[y]+=wt[x] ;
			}
			else {
				p[y] =x ;	wt[x]+=wt[y] ;
			}
		}
	}
	static int rt (int i) {
		while (p[i] != i) {
			i =p[p[i]] ;	i =p[i] ;
		}
		return i ;
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br =new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st==null || (!st.hasMoreElements())) 
			{
				try
				{
					st =new StringTokenizer(br.readLine());
				}
				catch(IOException e)
				{
					e.printStackTrace();
				}
				
			}
			return st.nextToken();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next()) ;
		}
	}
}