#include <bits/stdc++.h>
using namespace std;
long long int powmod(long long int a, long long int l, long long int md) {
  long long int res = 1;
  while (l) {
    if (l & 1) res = res * a % md;
    l /= 2;
    a = a * a % md;
  }
  return res;
}
long long int binpow(long long int a, long long int l) {
  long long int res = 1;
  while (l) {
    if (l & 1) res = res * a;
    l /= 2;
    a = a * a;
  }
  return res;
}
long long int invmod(long long int a, long long int md) {
  return powmod(a, md - 2, md);
}
void dfs(long long int ind, vector<vector<long long int> >& adj,
         vector<long long int>& visited) {
  visited[ind] = 1;
  for (auto x : adj[ind]) {
    if (visited[x] == 0) {
      dfs(x, adj, visited);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m, a, b;
    cin >> n >> m >> a >> b;
    vector<vector<long long int> > adj_a(n, vector<long long int>(0));
    vector<vector<long long int> > adj_b(n, vector<long long int>(0));
    for (long long int i = 0; i < m; i++) {
      long long int x, y;
      cin >> x >> y;
      if (x != a && y != a) {
        adj_a[x - 1].push_back(y - 1);
        adj_a[y - 1].push_back(x - 1);
      }
      if (x != b && y != b) {
        adj_b[x - 1].push_back(y - 1);
        adj_b[y - 1].push_back(x - 1);
      }
    }
    vector<long long int> visited_a(n, 0);
    vector<long long int> visited_b(n, 0);
    dfs(b - 1, adj_a, visited_a);
    dfs(a - 1, adj_b, visited_b);
    set<long long int> set1;
    set<long long int> set2;
    for (long long int i = 0; i < n; i++) {
      if (visited_a[i] && i != b - 1) {
        set1.insert(i);
      }
      if (visited_b[i] && i != a - 1) {
        set2.insert(i);
      }
    }
    long long int count1, count2, cnt = 0;
    for (auto x : set1) {
      if (set2.count(x)) cnt += 1;
    }
    count1 = set1.size() - cnt;
    count2 = set2.size() - cnt;
    cout << count1 * count2 << "\n";
  }
  return 0;
}
