
if __name__ == '__main__':
    t = int(input())
    for _ in range(t):
        n,m,a,b = map(int, input().split())
        g = [[] for _ in range(n)]
        for _ in range(m):
            u,v = map(int, input().split())
            g[u-1].append(v-1)
            g[v-1].append(u-1)
        a -= 1
        b -= 1
        sigs = [0]*n
        sigs[a] = -1
        sigs[b] = -1
        cur_sig = 0
        inv = {}
        cnt = {}
        for i in range(n):
            if sigs[i]:
                continue
            cur_sig += 1
            cnt[cur_sig] = 0
            inv[cur_sig] = set()
            def dfs(node):
                if node == a:
                    inv[cur_sig].add("A")
                if node == b:
                    inv[cur_sig].add("B")
                if sigs[node]:
                    return
                sigs[node] = cur_sig
                cnt[cur_sig] += 1
                for v in g[node]:
                    dfs(v)
            dfs(i)
        be = [k for k,v in inv.items() if len(v) == 1]
        # print(sigs)
        # print(inv)
        # print(cnt)
        if len(be) != 2:
            print(0)
            continue
        x = 1
        for b in be:
            x *= cnt[b]
        print(x)
            
        
        
        
        
        
            
        
        
    
        

