import java.io.*;
import java.util.*;

public class P606E {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        for(int i=0; i<t; i++) {
            String[] line = br.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int m = Integer.parseInt(line[1]);
            int a = Integer.parseInt(line[2]) - 1;
            int b = Integer.parseInt(line[3]) - 1;

            int[][] roads = new int[m][2];
            for(int j=0; j<m; j++) {
                line = br.readLine().split(" ");
                roads[j][0] = Integer.parseInt(line[0]) - 1;
                roads[j][1] = Integer.parseInt(line[1]) - 1;
            }

            ArrayList<ArrayList<Integer>> adjList = new ArrayList<>();
            for(int j=0; j<n; j++) {
                adjList.add(new ArrayList<Integer>());
            }

            for(int j=0; j<m; j++) {
                adjList.get(roads[j][0]).add(roads[j][1]);
                adjList.get(roads[j][1]).add(roads[j][0]);
            }

            DisjointSets djs = new DisjointSets(n);
            for(int j=0; j<m; j++) {
                if(roads[j][0] != a && roads[j][0] != b && roads[j][1] != a && roads[j][1] != b) {
                    djs.unionSet(roads[j][0], roads[j][1]);
                }
            }

            HashMap<Integer, Group> groups = new HashMap<>();

            for(int j=0; j<n; j++) {
                if(j != a && j != b) {
                    int g = djs.findSet(j);
                    if(groups.containsKey(g)) {
                        Group group = groups.get(g);
                        group.size++;
                    } else {
                        groups.put(g, new Group(1, false, false));
                    }
                }
            }

            for(Integer aNeighbor : adjList.get(a)) {
                if(aNeighbor != b) {
                    int g = djs.findSet(aNeighbor);
                    groups.get(g).aAdj = true;
                }
            }

            for(Integer bNeighbor : adjList.get(b)) {
                if(bNeighbor != a) {
                    int g = djs.findSet(bNeighbor);
                    groups.get(g).bAdj = true;
                }
            }

            int aOnlySize = 0;
            int bOnlySize = 0;

            for(Group group : groups.values()) {
                if(group.aAdj && !group.bAdj)
                    aOnlySize += group.size;
                else if(!group.aAdj && group.bAdj)
                    bOnlySize += group.size;
            }

            System.out.println(aOnlySize * bOnlySize);
        }
    }

    static class Group {
        int size;
        boolean aAdj;
        boolean bAdj;
        public Group(int size, boolean a, boolean b) {
            this.size = size;
            aAdj = a;
            bAdj = b;
        }
    }

    static class DisjointSets {
        int[] p;
        int[] rank;

        public DisjointSets(int size) {
            p = new int[size];
            rank = new int[size];
            for(int i=0; i<size; i++) {
                p[i] = i;
            }
        }

        int findSet(int i) {
            return p[i] == i ? i : (p[i] = findSet(p[i]));
        }

        boolean isSameSet(int i, int j) {
            return findSet(i) == findSet(j);
        }

        void unionSet(int i, int j) {
            if(!isSameSet(i, j)) {
                int x = findSet(i), y = findSet(j);
                if(rank[x] > rank[y]) p[y] = x;
                else {
                    p[x] = y;
                    if(rank[x] == rank[y]) rank[y]++;
                }
            }
        }


    }

}
