#include <bits/stdc++.h>
using namespace std;
void first_dfs(vector<vector<int> > &data, vector<int> &used, int cur, int v) {
  if (cur != v) {
    if (used[cur] == 0)
      used[cur] = 1;
    else
      used[cur] = 3;
    for (auto i : data[cur]) {
      if (used[i] != 1 && used[i] != 3) first_dfs(data, used, i, v);
    }
  }
}
void second_dfs(vector<vector<int> > &data, vector<int> &used, int cur, int v) {
  if (cur != v) {
    if (used[cur] == 0)
      used[cur] = 2;
    else
      used[cur] = 3;
    for (auto i : data[cur]) {
      if (used[i] != 2 && used[i] != 3) second_dfs(data, used, i, v);
    }
  }
}
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;
    --a;
    --b;
    vector<vector<int> > data(n);
    vector<int> used(n, 0);
    for (int i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y;
      x--;
      y--;
      data[x].push_back(y);
      data[y].push_back(x);
    }
    first_dfs(data, used, a, b);
    second_dfs(data, used, b, a);
    long long ans1 = 0, ans2 = 0;
    for (int i = 0; i < n; ++i) {
      if (used[i] == 1 && i != a)
        ++ans1;
      else if (used[i] == 2 && i != b)
        ++ans2;
    }
    cout << ans1 * ans2 << endl;
  }
  return 0;
}
