
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class TwoFairs implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    int t = in.ni();
    while (t-- > 0) {
      graph = new ArrayList<>();
      n = in.ni();
      int m = in.ni(), x = in.ni(), y = in.ni();
      for (int i = 0; i <= n; i++) {
        graph.add(new ArrayList<>());
      }
      for (int i = 0; i < m; i++) {
        int u = in.ni(), v = in.ni();
        graph.get(u).add(v);
        graph.get(v).add(u);
      }
      out.println(go(x, y) * go(y, x));
    }
  }

  private long go(int x, int y) {
    level = new int[n + 1];
    low = new int[n + 1];
    articulation = new boolean[n + 1];
    seen = new boolean[n + 1];
    level[x] = 1;
    dfs(x, 0, y, false);
    long count = 0;
    if (articulation[y]) {
      for (int i = 1; i <= n; i++) {
        if (seen[i]) {
          count++;
        }
      }
    }
    return count;
  }

  private List<List<Integer>> graph;
  private int n;
  private int[] level, low;
  private boolean[] articulation, seen;

  private void dfs(int u, int p, int target, boolean targetSeen) {
    int children = 0;
    seen[u] = targetSeen;
    for (int to : graph.get(u)) {
      if (to == p) continue;
      if (level[to] == 0) {
        low[to] = level[to] = level[u] + 1;
        dfs(to, u, target, targetSeen | (u == target));
        low[u] = Math.min(low[u], low[to]);
        if (low[to] >= level[u] && p != 0) {
          articulation[u] = true;
        }
        children++;
      } else {
        low[u] = Math.min(low[u], level[to]);
      }
    }
    if (p == 0 && children > 1) {
      articulation[u] = true;
    }
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int ni() {
      return Integer.parseInt(next());
    }

    public long nl() {
      return Long.parseLong(next());
    }

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (TwoFairs instance = new TwoFairs()) {
      instance.solve();
    }
  }
}
