import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Arrays;

class Main {
  public static void main(String[] args) {
    In in = new In();
    Out out = new Out();
    out.SysInit(); 
    test(in, out);
  }
  
   public static void test(In in, Out out) {
        in.open("public/custom.in");
        out.compareTo("public/custom.out");
        int numTests = in.readInt();
        
        for (int t = 0; t < numTests; t++) {
            int n = in.readInt(); 
            int m = in.readInt(); 
            int start = in.readInt();
            int end = in.readInt();
            
            ArrayList<ArrayList<Integer>> E = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                E.add(new ArrayList<>());
            }
            
            for (int i = 0; i < m; i++) {
                int u = in.readInt();
                int v = in.readInt();
                E.get(u).add(v);
                E.get(v).add(u);
            }
          int res = numPaths(start, end, n, m, E);
          out.println(res);
        }
    }
    
    // =========================================================================================
    // Path Counting using BFS                                                                //
    // =========================================================================================
    public static int numPaths(int u, int v, int n, int m, ArrayList<ArrayList<Integer>> E) {
        // TODO: Count the paths from u to v using BFS
        Queue<Integer> q = new LinkedList<Integer>();
        int[] paths = new int[n];
        int[] dist = new int[n];
        Arrays.fill(dist, -1); // initialize distances to -1
        
        q.add(u); // add starting vertex to queue
        paths[u] = 1; // ... and set the base case
        dist[u] = 0;
        
        while(!q.isEmpty()) {
          int curr = q.poll(); // dequeue next vertex in the queue
          if (curr == v) break; // no more paths of length dist[v] can be found => stop BFS
          
          // Iterate over all neighbors in adjacency list (E.get(curr))
          for (int neigh: E.get(curr)) {
            // If neighbor hasn't been visited before (dist[neigh] array is still -1)
            if (dist[neigh] < 0) {
              dist[neigh] = dist[curr] + 1; // update distance
              q.add(neigh); // add to queue (only for the first visit)
            }
            // Path counting logic: number of paths to reach neigh in dist[neigh] number of steps (i.e., in the shortest number of steps possible)
            // must be number of ways to reach its neighbors in dist[neigh]-1 steps
            // Note the check 'dist[neigh] == dist[curr] + 1' to ensure that we only count shortest paths!
            if (dist[neigh] == dist[curr] + 1) paths[neigh] += paths[curr];
          }
        }
        
        return paths[v];
    }
}