#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int maxm = 5e5 + 5;
const int INF = 2e9;
struct edge {
  int to, next;
} G[maxm << 1];
int tot, head[maxn];
void addEdge(int u, int v) {
  G[tot] = {v, head[u]};
  head[u] = tot++;
}
int T, n, m, a, b, vis[maxn], ha[maxn];
void dfs(int u, int fa) {
  vis[u] = 0;
  if (u == b) {
    vis[u] = 1;
    return;
  }
  int i, v;
  for (i = head[u]; i != -1; i = G[i].next) {
    v = G[i].to;
    if (v == fa) continue;
    if (vis[v] == -1) {
      dfs(v, u);
      if (vis[v] == 1) vis[u] = 1;
    } else if (vis[v] == 1)
      vis[u] = 1;
  }
}
int dfs2(int u) {
  ha[u] = 1;
  int i, v, res = 1;
  for (i = head[u]; i != -1; i = G[i].next) {
    v = G[i].to;
    if (vis[v] == 1 || ha[v]) continue;
    res += dfs2(v);
  }
  return res;
}
int dfs3(int u, int fa) {
  int i, v;
  for (i = head[u]; i != -1; i = G[i].next) {
    v = G[i].to;
    if (v == fa) continue;
    if (vis[v] == 0) {
      vis[v] = -1;
      dfs3(v, u);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> T;
  while (T--) {
    cin >> n >> m >> a >> b;
    tot = 0;
    for (int i = 1; i <= n; i++) {
      head[i] = vis[i] = -1;
      ha[i] = 0;
    }
    int u, v;
    for (int i = 1; i <= m; i++) {
      cin >> u >> v;
      addEdge(u, v);
      addEdge(v, u);
    }
    dfs(a, -1);
    dfs3(a, -1);
    vector<long long> ans;
    for (int i = 1; i <= n; i++) {
      if (vis[i] == 1 || ha[i]) continue;
      ans.push_back(dfs2(i));
    }
    if (ans.size() < 2)
      cout << 0 << "\n";
    else {
      long long res = 1;
      for (long long &i : ans) res *= i;
      cout << res << "\n";
    }
  }
}
