from sys import stdin


def input():
    return stdin.readline()[:-1]


def intput():
    return int(input())


def sinput():
    return input().split()


def intsput():
    return map(int, sinput())


# Code

t = intput()

for _ in range(t):
    n, m, a, b = intsput()
    colors = [0] * (n + 1)
    colors[a] = 'a'
    colors[b] = 'b'

    roads = {}

    for i in range(m):
        x, y = intsput()
        if x not in roads:
            roads[x] = []
        if y not in roads:
            roads[y] = []
        roads[x].append(y)
        roads[y].append(x)
    
    for i in range(1, n + 1):
        if i not in (a, b):
            break
    start = i

    visited = set([start])
    colors[start] = 1
    adj = roads[start]
    meta, metb = False, False
    while adj:
        nxt = adj.pop()
        if nxt == a:
            meta = True
        elif nxt == b:
            metb = True
        elif nxt not in visited:
            visited.add(nxt)
            colors[nxt] = 1
            adj += roads[nxt]
    
    col1 = (meta, metb)

    for i in range(1, n + 1):
        if i not in (a, b) and i not in visited:
            break
    else:
        print(0)
        continue

    start = i

    visited = set([start])
    colors[start] = 2
    adj = roads[start]
    meta, metb = False, False
    while adj:
        nxt = adj.pop()
        if nxt == a:
            meta = True
        elif nxt == b:
            metb = True
        elif nxt not in visited:
            visited.add(nxt)
            colors[nxt] = 2
            adj += roads[nxt]
    
    col2 = (meta, metb)

    #print(colors[1:])

    count1, count2, count3 = 0, 0, 0
    for i in range(1, len(colors)):
        if colors[i] == 1:
            count1 += 1
        elif colors[i] == 2:
            count2 += 1
        elif colors[i] == 0:
            count3 += 1
    
    #print(count1, count2, count3)
    if col1 == (True, True):
        print(count2 * count3)
    elif col2 == (True, True):
        print(count1 * count3)
    else:
        print(count1 * count2)
