import sys
from collections import defaultdict

# inf = open('input.txt', 'r')
# reader = (map(int, line.split()) for line in inf)
reader = (map(int, line.split()) for line in sys.stdin)

def dfs(s, comp, omit):
    stack = [s]
    while stack:
        v = stack.pop()
        if not visited[v]:
            visited[v] = True
            if v != omit:
                comp[0] += 1
            stack.extend(g[v])

def Cn2(n):
    return n * (n - 1) // 2

t, = next(reader)
for _ in range(t):
    n, m, a, b = next(reader) # v(G), e(G), a, b
    a -= 1
    b -= 1
    
    g = defaultdict(list)
    for i in range(m):
        v, to = next(reader)
        v -= 1
        to -= 1
        g[v].append(to)
        g[to].append(v)

    visited = [False] * n
    visited[a] = True
    comps_a = []
    for s in range(n):
        if not visited[s]:
            comps_a.append([0])
            dfs(s, comps_a[-1], omit=b)

    visited = [False] * n
    visited[b] = True
    comps_b = []
    for s in range(n):
        if not visited[s]:
            comps_b.append([0])
            dfs(s, comps_b[-1], omit=a)        

    visited = [False] * n
    visited[a] = True
    visited[b] = True
    comps_ab = []
    for s in range(n):
        if not visited[s]:
            comps_ab.append([0])
            dfs(s, comps_ab[-1], omit=n+1)        

    allV = n - 2
    N_a = 0  # passes a
    for comp in comps_a:
        k = comp[0]
        allV -= k
        N_a += k * allV

    allV = n - 2
    N_b = 0  # passes b
    for comp in comps_b:
        k = comp[0]
        allV -= k
        N_b += k * allV
    
    allV = n - 2
    N_0 = 0  # not passes a or b
    for comp in comps_ab:
        k = comp[0]
        allV -= k
        N_0 += Cn2(k)
    
    N_all = Cn2(n - 2)
    N_ab = N_0 + N_a + N_b - N_all

    print(N_ab)

# inf.close()