import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')


def find(x,same):
    tmp = []
    while same[x]!=x:
        tmp.append(x)
        x = same[x]
    for v in tmp:
        same[v] = x
    return same[x]

def merge(a,b,same):
    a = find(a,same)
    b = find(b,same)
    if a==b:
        return
    else:
        same[a] = same[b]
        return 

t = int(input())
for _ in range(t):
    n,m,a,b = map(int,raw_input().split(" "))
    a,b = min(a,b),max(a,b)
    pairs = []
    for i in range(m):
        u,v = map(int,raw_input().split(" "))
        pairs.append((u,v))
    same = range(n+1)
    As = []
    Bs = []
    for x,y in pairs:
        if x!=a and x!=b and y!=a and y!=b:
            merge(x,y,same)
        elif x == a or y == a:
            As.append((x,y))
        else:
            Bs.append((x,y))
    for i in range(1,n+1):
        find(i,same)
    sameA = [0]*(1+n)
    sameB = [0]*(1+n)
    for i in range(n+1):
        sameA[i] = same[i]
        sameB[i] = same[i]

    for x,y in As:        
        if (x == a and y == b) or (x ==b and y == a):
            continue
        merge(x,y,sameA)

    for x,y in Bs:        
        if (x == a and y == b) or (x ==b and y == a):
            continue
        merge(x,y,sameB)

    find(a,sameA)
    find(b,sameB)
    cnt1 = 0
    cnt2 = 0
    for i in range(1,n+1):
        find(i,sameA)
        find(i,sameB)
        if sameA[i] == sameA[a]:
            cnt1 += 1
        if sameB[i] == sameB[b]:
            cnt2 += 1

    print (n-cnt1-1)*(n-cnt2-1)







