#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    vector<int> ed[n + 1];
    for (int i = 0; i < m; i++) {
      int u, v;
      cin >> u >> v;
      ed[u].push_back(v);
      ed[v].push_back(u);
    }
    queue<int> q;
    bool vis[n + 1], vis2[n + 1];
    memset(vis, false, sizeof vis);
    memset(vis2, false, sizeof vis2);
    q.push(a);
    vis[a] = true;
    int h = 0;
    while (!q.empty()) {
      int f = q.front();
      q.pop();
      h += f != a;
      for (int e : ed[f]) {
        if (!vis[e] && e != b) {
          q.push(e);
          vis[e] = true;
        }
      }
    }
    int h2 = 0;
    q.push(b);
    vis2[b] = true;
    while (!q.empty()) {
      int f = q.front();
      q.pop();
      h2 += f != b;
      for (int e : ed[f]) {
        if (!vis2[e] && e != a) {
          q.push(e);
          vis2[e] = true;
        }
      }
    }
    int com = 0;
    for (int i = 1; i < n + 1; i++) com += vis[i] && vis2[i];
    cout << (long long int)(h - com) * (h2 - com) << '\n';
  }
}
