#include <bits/stdc++.h>
using namespace std;
long long done = 0;
void dfs(vector<vector<long long> > &adj, vector<long long> &visited,
         long long src, vector<long long> &tbr, long long b) {
  if (src == b) {
    done = 1;
    return;
  }
  tbr.push_back(src);
  visited[src] = 1;
  for (long long i = 0; i < adj[src].size(); i++) {
    if (!visited[adj[src][i]]) {
      dfs(adj, visited, adj[src][i], tbr, b);
    }
  }
}
long long num = 0;
void dfs2(vector<vector<long long> > &adj, vector<long long> &visited,
          long long src) {
  visited[src] = 1;
  num++;
  for (long long i = 0; i < adj[src].size(); i++) {
    if (!visited[adj[src][i]]) dfs2(adj, visited, adj[src][i]);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    num = 0;
    done = 0;
    long long v, e, a, b;
    cin >> v >> e >> a >> b;
    vector<vector<long long> > adj(v + 1);
    for (long long i = 0; i < e; i++) {
      long long v1, v2;
      cin >> v1 >> v2;
      adj[v1].push_back(v2);
      adj[v2].push_back(v1);
    }
    vector<long long> visited(v + 1, 0);
    visited[a] = 1;
    vector<long long> tbr;
    for (long long i = 0; i < ((long long)adj[a].size()); i++) {
      dfs(adj, visited, adj[a][i], tbr, b);
      if (done == 1) {
        done = 0;
      } else {
        tbr.clear();
      }
    }
    for (long long i = 0; i < v + 1; i++) visited[i] = 0;
    for (auto x : tbr) visited[x] = 1;
    long long k = 0;
    long long ans[2] = {0, 0};
    visited[b] = 1;
    dfs2(adj, visited, a);
    ans[k] = num - 1;
    num = 0;
    k++;
    visited[b] = 0;
    visited[a] = 1;
    dfs2(adj, visited, b);
    ans[k] = num - 1;
    cout << (ans[0] * ans[1]) << "\n";
  }
  return 0;
}
