#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 50;
bool vis[N];
vector<long long> comp;
vector<long long> gone[N + 1];
vector<long long> gtwo[N + 1];
void __print(long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  long long f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
void dfs(long long node, long long tc) {
  vis[node] = 1;
  comp.push_back(node);
  for (auto ch : (tc == 1 ? gone[node] : gtwo[node])) {
    if (!vis[ch]) {
      dfs(ch, tc);
    }
  }
}
void solve() {
  long long n, m;
  cin >> n >> m;
  long long U, V;
  cin >> U >> V;
  for (long long x = 0; x < m; x++) {
    long long u, v;
    cin >> u >> v;
    if (u != U and v != U) {
      gone[u].push_back(v);
      gone[v].push_back(u);
    }
    if (u != V and v != V) {
      gtwo[u].push_back(v);
      gtwo[v].push_back(u);
    }
  }
  long long cntX = 0;
  for (long long x = 1; x <= n; x++) {
    if (!vis[x]) {
      comp.clear();
      dfs(x, 1);
      long long yes = 1;
      if (comp.size() == 1) {
        if (comp.back() == U) {
          yes = 0;
        }
      }
      for (long long cx : comp) {
        if (cx == V) yes = 0;
      }
      if (yes) {
        cntX += comp.size();
      }
    }
  }
  for (long long x = 1; x <= n; x++) vis[x] = false;
  long long cntY = 0;
  for (long long x = 1; x <= n; x++) {
    if (!vis[x]) {
      comp.clear();
      dfs(x, 2);
      long long yes = 1;
      if (comp.size() == 1) {
        if (comp.back() == V) {
          yes = 0;
        }
      }
      for (long long cx : comp) {
        if (cx == U) yes = 0;
      }
      if (yes) {
        cntY += comp.size();
      }
    }
  }
  long long ans = cntX * cntY;
  cout << ans << endl;
  for (long long x = 1; x <= n; x++) {
    gone[x].clear();
    gtwo[x].clear();
    vis[x] = false;
  }
}
int32_t main() {
  long long tc;
  cin >> tc;
  while (tc--) {
    solve();
  }
  return 0;
}
