#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 9;
vector<long long> g[maxn];
long long n, m, a, b;
bool used[maxn];
pair<long long, long long> dfs(long long v, long long u) {
  used[v] = 1;
  pair<long long, long long> ans(1, v == u);
  for (long long to : g[v]) {
    if (!used[to]) {
      pair<long long, long long> cur = dfs(to, u);
      ans.first += cur.first;
      ans.second |= cur.second;
    }
  }
  return ans;
}
void solve() {
  cin >> n >> m >> a >> b;
  a--;
  b--;
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
  }
  long long sz1 = 0, sz2 = 0;
  for (long long i = 0; i < n; i++) used[i] = 0;
  used[a] = 1;
  for (long long to : g[a]) {
    if (!used[to]) {
      pair<long long, long long> cur = dfs(to, b);
      if (!cur.second) sz1 += cur.first;
    }
  }
  for (long long i = 0; i < n; i++) used[i] = 0;
  used[b] = 1;
  for (long long to : g[b]) {
    if (!used[to]) {
      pair<long long, long long> cur = dfs(to, a);
      if (!cur.second) sz2 += cur.first;
    }
  }
  for (long long i = 0; i < n; i++) {
    g[i].resize(0);
    g[i].shrink_to_fit();
  }
  cout << sz1 * sz2 << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  for (long long j = 0; j < t; j++) solve();
}
