#include <bits/stdc++.h>
using namespace std;
template <typename t1, typename t2>
using umap = unordered_map<t1, t2>;
template <typename t>
using uset = unordered_set<t>;
vector<bool> used;
void dfs(int s, vector<vector<int> >& g) {
  used[s] = 1;
  for (int x : g[s]) {
    if (!used[x]) {
      dfs(x, g);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    used = vector<bool>(n);
    vector<vector<int> > g(n);
    a--, b--;
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      x--, y--;
      g[x].push_back(y);
      g[y].push_back(x);
    }
    used[a] = 1;
    int c1 = 0, c2 = 0;
    dfs(b, g);
    for (int i = 0; i < n; i++) {
      if (!used[i]) {
        c1++;
      }
      used[i] = !used[i];
    }
    used[b] = 1;
    dfs(a, g);
    for (int i = 0; i < n; i++) {
      if (!used[i]) {
        c2++;
      }
      used[i] = !used[i];
    }
    cout << c1 * c2 << "\n";
  }
  return 0;
}
