import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    TreeMap<Integer, Integer> comp_a;
    TreeMap<Integer, Integer> comp_b;
    TreeMap<Integer, Integer> comp_ab;
    ArrayList<Integer> graph[];
    boolean[] used;
    int a;
    int b;

    void dfs_a(int v, int comp) {
        used[v] = true;
        if (v != b) comp_a.put(comp, comp_a.getOrDefault(comp, 0) + 1);
        for (Integer to : graph[v]) {
            if (to == a) continue;
            if (!used[to]) dfs_a(to, comp);
        }
    }

    void dfs_b(int v, int comp) {
        used[v] = true;
        if (v != a) comp_b.put(comp, comp_b.getOrDefault(comp, 0) + 1);
        for (Integer to : graph[v]) {
            if (to == b) continue;
            if (!used[to]) dfs_b(to, comp);
        }
    }

    void dfs_ab(int v, int comp) {
        used[v] = true;
        comp_ab.put(comp, comp_ab.getOrDefault(comp, 0) + 1);
        for (Integer to : graph[v]) {
            if (to == b || to == a) continue;
            if (!used[to]) dfs_ab(to, comp);
        }
    }

    void run() throws IOException {
        int q = nextInt();
        while (q-- > 0) {
            comp_a = new TreeMap<>();
            comp_b = new TreeMap<>();
            comp_ab = new TreeMap<>();
            int n = nextInt();
            int m = nextInt();
            a = nextInt() - 1;
            b = nextInt() - 1;
            graph = new ArrayList[n];
            for (int i = 0; i < graph.length; i++) {
                graph[i] = new ArrayList<>();
            }
            for (int i = 0; i < m; i++) {
                int from = nextInt() - 1;
                int to = nextInt() - 1;
                graph[from].add(to);
                graph[to].add(from);
            }
            used = new boolean[n];
            int c = 1;
            for (int i = 0; i < used.length; i++) {
                if (!used[i] && i != a) {
                    dfs_a(i, c);
                    c++;
                }
            }
            used = new boolean[n];
            c = 1;
            for (int i = 0; i < used.length; i++) {
                if (!used[i] && i != b) {
                    dfs_b(i, c);
                    c++;
                }
            }
            used = new boolean[n];
            c = 1;
            for (int i = 0; i < used.length; i++) {
                if (!used[i] && i != a && i != b) {
                    dfs_ab(i, c);
                    c++;
                }
            }
            long ans = (n - 2) * (n - 3) / 2;
            for (Integer x : comp_a.keySet()) ans -= comp_a.get(x) * (comp_a.get(x) - 1) / 2;
            for (Integer x : comp_b.keySet()) ans -= comp_b.get(x) * (comp_b.get(x) - 1) / 2;
            for (Integer x : comp_ab.keySet()) ans += comp_ab.get(x) * (comp_ab.get(x) - 1) / 2;
            pw.println(ans);
        }
        pw.close();
    }

    class point implements Comparable<point> {
        int x, y;

        public point(int a, int b) {
            x = a;
            y = b;
        }

        @Override
        public int compareTo(point o) {
            if (o.y == this.y) return Integer.compare(o.x, this.x);
            return -Integer.compare(o.y, this.y);
        }

    }

    long mod = (long) 1e9 + 7;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    //BufferedReader br = new BufferedReader(new FileReader("qual.in"));

    StringTokenizer st = new StringTokenizer("");
    PrintWriter pw = new PrintWriter(System.out);
    //PrintWriter pw = new PrintWriter("qual.out");

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    String next() throws IOException {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public Main() throws FileNotFoundException {
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}