#########################################################################################################\
#########################################################################################################
###################################The_Apurv_Rathore#####################################################
#########################################################################################################
#########################################################################################################
import sys,os,io
from sys import stdin
from types import GeneratorType
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_left , bisect_right
import math 




alphabets = list('abcdefghijklmnopqrstuvwxyz')



#for deep recursion__________________________________________-
def bootstrap(f, stack=[]):
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break
                    to = stack[-1].send(to)
            return to

    return wrappedfunc

def ncr(n, r, p):  
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den,p - 2, p)) % p

def primeFactors(n): 
    l = []
    while n % 2 == 0: 
        l.append(2)
        n = n / 2
    for i in range(3,int(math.sqrt(n))+1,2): 
        while n % i== 0: 
            l.append(int(i))
            n = n / i 
    if n > 2: 
        l.append(n)
    c = dict(Counter(l))
    return list(set(l))
    # return c

def power(x, y, p) : 
	res = 1
	x = x % p 
	if (x == 0) : 
		return 0
	while (y > 0) : 
		if ((y & 1) == 1) : 
			res = (res * x) % p 
		y = y >> 1	 # y = y/2 
		x = (x * x) % p 		
	return res 

#____________________GetPrimeFactors in log(n)________________________________________
def sieveForSmallestPrimeFactor():
    MAXN = 100001
    spf = [0 for i in range(MAXN)]
    spf[1] = 1
    for i in range(2, MAXN):
        spf[i] = i
    for i in range(4, MAXN, 2):
        spf[i] = 2
    for i in range(3, math.ceil(math.sqrt(MAXN))):
        if (spf[i] == i):
            for j in range(i * i, MAXN, i): 
                if (spf[j] == j):
                    spf[j] = i
    return spf
def getPrimeFactorizationLOGN(x):
    spf = sieveForSmallestPrimeFactor()
    ret = list()
    while (x != 1):
        ret.append(spf[x])
        x = x // spf[x]  
    return ret
#____________________________________________________________



def SieveOfEratosthenes(n): 
    #time complexity = nlog(log(n))
    prime = [True for i in range(n+1)]
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime
def si():
    return input()
def divideCeil(n,x):
    if (n%x==0):
        return n//x
    return n//x+1
def ii():
    return int(input())
def li():
    return list(map(int,input().split()))

#__________________________TEMPLATE__________________OVER_______________________________________________________


if(os.path.exists('input.txt')):
    sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w") 
else:
    input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline


def solve():
    n,m,a,b = li()
    a-=1
    b-=1
    adj = [[] for i in range(n)]
    for i in range(m):
        u,v = li()
        u-=1
        v-=1
        adj[u].append(v)
        adj[v].append(u)
    
    visa = [False]*n 
    # @bootstrap

    def dfsa(node,parent):
        st = [node]
        while(st!=[]):
            node = st.pop(-1)
            for child in adj[node]:
                if child==parent or child==b:
                    continue 
                if visa[child]==False:
                    visa[child]=True 
                    st.append(child)

    # def dfsa(node,parent):
    #     for child in adj[node]:
    #         if child==parent or child==b:
    #             continue 
    #         if visa[child]==False:
    #             visa[child]=True 
    #             yield dfsa(child,node)
    visa[a]=True
    dfsa(a,-1)
    visb = [False]*n 
    visb[b]=True

    def dfsb(node,parent):
        st = [node]
        while(st!=[]):
            node = st.pop(-1)
            for child in adj[node]:
                if child==parent or child==a:
                    continue 
                if visb[child]==False:
                    visb[child]=True 
                    st.append(child)
    # @bootstrap
    # def dfsb(node,parent):
    #     for child in adj[node]:
    #         if child==parent or child==a:
    #             continue 
    #         if visb[child]==False:
    #             visb[child]=True 
    #             yield dfsb(child,node)
    dfsb(b,-1)
    # print(visa)
    # print(visb)
    visbyanotb = 0
    visbybnota = 0
    for i in range(n):
        if i==a or i==b:
            continue
        if visa[i]==False and visb[i]==True:
            visbyanotb+=1
        if visa[i]==True and visb[i]==False:
            visbybnota+=1
    # print(visbybnota,visbyanotb)
    print(visbybnota*visbyanotb)

    




t = 1
t = ii()
for _ in range(t):
    solve()
