#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
inline void smax(int &x, int y) { x = max(x, y); }
inline void smin(int &x, int y) { x = min(x, y); }
ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); }
ll n, m, a, b;
vector<vector<int> > gr;
vector<int> vis;
ll con = 0;
int dfs(int s, int prt) {
  vis[s] = 1;
  con++;
  int f = 0;
  if (prt == s) f = 1;
  for (__typeof(gr[s].size()) i = (0) - ((0) > (gr[s].size()));
       i != (gr[s].size()) - ((0) > (gr[s].size()));
       i += 1 - 2 * ((0) > (gr[s].size()))) {
    int x = gr[s][i];
    if (!vis[x]) {
      if (dfs(x, prt) == 1) f = 1;
    }
  }
  return f;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  int tcase;
  cin >> tcase;
  for (__typeof(tcase + 1) tc = (1) - ((1) > (tcase + 1));
       tc != (tcase + 1) - ((1) > (tcase + 1));
       tc += 1 - 2 * ((1) > (tcase + 1))) {
    cin >> n >> m >> a >> b;
    gr.resize(0);
    vis.resize(0);
    gr.resize(n + 1);
    vis.resize(n + 1);
    for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));
         i += 1 - 2 * ((0) > (m))) {
      int x, y;
      cin >> x >> y;
      gr[x].push_back(y);
      gr[y].push_back(x);
    }
    ll con1 = 0;
    vis[a] = 1;
    for (__typeof(gr[a].size()) i = (0) - ((0) > (gr[a].size()));
         i != (gr[a].size()) - ((0) > (gr[a].size()));
         i += 1 - 2 * ((0) > (gr[a].size()))) {
      if (vis[gr[a][i]]) continue;
      con = 0;
      int tch = dfs(gr[a][i], b);
      if (tch == 0) {
        con1 += con;
      }
    }
    vis.resize(0);
    vis.resize(n + 1);
    vis[b] = 1;
    ll con2 = 0;
    for (__typeof(gr[b].size()) i = (0) - ((0) > (gr[b].size()));
         i != (gr[b].size()) - ((0) > (gr[b].size()));
         i += 1 - 2 * ((0) > (gr[b].size()))) {
      con = 0;
      if (vis[gr[b][i]]) continue;
      int tch = dfs(gr[b][i], a);
      if (tch == 0) {
        con2 += con;
      }
    }
    cout << con2 * con1 << "\n";
  }
}
