#include <bits/stdc++.h>
using namespace std;
const long long int INF = 3000000000000000000;
map<long long int, long long int> dist, dist1;
bool vis[5000005], vis1[5000005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1, xp = 1;
  cin >> t;
  while (t--) {
    long long int i = 0, h, j = 0, x = 0, y = 0, n, m, k = 0, r = 0, l = 0,
                  o = 0, cnt1 = INT_MAX, cnt2 = 0, cnt3 = INT_MIN, cnt4 = 0,
                  min1 = INT_MIN;
    cin >> n >> m >> l >> r;
    vector<long long int> adj[n];
    for (i = 0; i < m; i++) {
      cin >> x >> y;
      x--;
      y--;
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    l--;
    r--;
    long long int dp[n], dp1[n];
    for (i = 0; i < n; i++) {
      dp[i] = INT_MAX;
      dp1[i] = INT_MAX;
    }
    priority_queue<long long int> q;
    q.push(l);
    dp[l] = 0;
    while (!q.empty()) {
      x = q.top();
      q.pop();
      for (auto y : adj[x]) {
        if (dp[y] > dp[x] + 1) {
          dp[y] = dp[x] + 1;
          q.push(y);
        }
      }
    }
    q.push(r);
    dp1[r] = 0;
    while (!q.empty()) {
      x = q.top();
      q.pop();
      for (auto y : adj[x]) {
        if (dp1[y] > dp1[x] + 1) {
          dp1[y] = dp1[x] + 1;
          q.push(y);
        }
      }
    }
    for (i = 0; i < n; i++) {
      if (dp[i] < dp1[i] && dp[i] != 0 && dp1[i] != 0) {
        cnt2++;
      } else if (dp[i] > dp1[i] && dp[i] != 0 && dp1[i] != 0)
        cnt4++;
    }
    cout << cnt2 * cnt4 << endl;
  }
}
