from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy

int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7

test = int_input()

set1 = []
n = 0
def dfs(graph,start,forbidden):
    Stack = [start]
    result = set([])
    visited = [False]*(n+1)
    while(Stack):
        children = Stack.pop()
        for items in graph[children]:
            if items == forbidden or visited[items]:
                continue
            else:
                visited[items] = True
                result.add(items)
                Stack.append(items)

    return result-{start}

for _ in range(test):

    n,m,a,b = multi_int_input()
    graph = {}
    for i in range(1,n+1):
        graph[i] = []
    for i in range(m):
        u,v = multi_int_input()
        graph[u].append(v)
        graph[v].append(u)

    result1 = dfs(graph,a,b)
    result2 = dfs(graph,b,a)

    print((len(result1-result2))*(len(result2-result1)))