#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, m, a, b;
vector<int> adj[N];
int vis[N];
void go(int x, int y, int m) {
  queue<int> q;
  q.push(x);
  vis[x] |= m;
  while (q.size()) {
    int cur = q.front();
    q.pop();
    for (int i : adj[cur]) {
      if (i == y) continue;
      if (vis[i] & m) continue;
      vis[i] |= m;
      q.push(i);
    }
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d %d %d", &n, &m, &a, &b);
    for (int i = 1; i <= n; i++) vis[i] = 0, adj[i].clear();
    for (int i = 0; i < m; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    go(a, b, 1);
    go(b, a, 2);
    int aa = 0, bb = 0;
    vis[a] = 0;
    vis[b] = 0;
    for (int i = 1; i <= n; i++) {
      aa += ((vis[i] & 1) == 1) * ((vis[i] & 2) == 0),
          bb += ((vis[i] & 2) == 2) * ((vis[i] & 1) == 0);
    }
    printf("%lld\n", 1LL * aa * bb);
  }
}
